Skip to content

Commit d92e53e

Browse files
committed
+ mask valid/invalid css feedback
+ ssn mask
1 parent b1714cd commit d92e53e

File tree

7 files changed

+100
-21
lines changed

7 files changed

+100
-21
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## 1.0.1 - 2022.11.28
6+
```
7+
+ mask valid/invalid css feedback
8+
+ ssn mask
9+
```
10+
511
## 1.0.0 - 2022.11.28
6-
### Initial release
12+
Initial release
713

composer.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
"masked",
77
"fields",
88
"mask",
9-
"validation"
9+
"formatting",
10+
"validation",
11+
"cp"
1012
],
11-
"version": "1.0.0",
13+
"version": "1.0.1",
1214
"type": "craft-plugin",
1315
"license": "MIT",
1416
"authors": [

src/Plugin.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919
use yii\base\Event;
2020
use craft\services\Fields;
2121

22-
/*
23-
* Class MixManifest
24-
*/
2522
class Plugin extends BasePlugin
2623
{
2724
// Properties

src/assets/Assets.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ public function init()
2020
$this->sourcePath = '@leowebguy/maskedfields/assets';
2121
$this->depends = [CpAsset::class];
2222

23+
$this->css = [
24+
'css/cp.css'
25+
];
26+
2327
$this->js = [
2428
'js/jquery.mask.min.js',
2529
'js/cp.js'

src/assets/css/cp.css

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
.valid {
2+
box-shadow: 0 0 1px 1px rgb(66, 185, 66, .65);
3+
position: relative;
4+
}
5+
6+
.glow-green {
7+
-webkit-animation: glow-green 500ms linear;
8+
-moz-animation: glow-green 500ms linear;
9+
animation: glow-green 500ms linear;
10+
}
11+
12+
@keyframes glow-green {
13+
0% {
14+
box-shadow: 0 0 2px 2px rgb(66, 185, 66, 1)
15+
}
16+
100% {
17+
box-shadow: 0 0 0 0 rgb(255, 255, 255, 0)
18+
}
19+
}
20+
21+
.glow-red {
22+
-webkit-animation: glow-red 500ms linear;
23+
-moz-animation: glow-red 500ms linear;
24+
animation: glow-red 500ms linear;
25+
}
26+
27+
@keyframes glow-red {
28+
0% {
29+
box-shadow: 0 0 2px 2px rgba(192, 13, 13, 1)
30+
}
31+
100% {
32+
box-shadow: 0 0 0 0 rgb(255, 255, 255, 0)
33+
}
34+
}

src/assets/js/cp.js

Lines changed: 45 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,47 @@
11
(($) => {
2-
$('.date-mask').mask('00/00/0000', {placeholder: 'mm/dd/yyyy'})
3-
$('.time-mask').mask('00:00:00', {placeholder: 'hh:mm:ss'})
4-
$('.datetime-mask').mask('00/00/0000 00:00:00', {placeholder: 'mm/dd/yyyy hh:mm:ss'})
5-
$('.cep-mask').mask('00000-000', {placeholder: '_____-___'})
6-
$('.zip-mask').mask('00000', {placeholder: '_____'})
7-
$('.phonebr-mask').mask('(00) 0000-0000', {placeholder: '(__) ____-____'})
8-
$('.phoneus-mask').mask('(000) 000-0000', {placeholder: '(___) ___-____'})
9-
$('.ip-mask').mask('099.099.099.099', {placeholder: '___.___.___.___'})
10-
$('.cnpj-mask').mask('00.000.000/0000-00', {placeholder: '__.___.___/____-__', reverse: true})
11-
$('.cpf-mask').mask('000.000.000-00', {placeholder: '___.___.___-__', reverse: true})
12-
$('.itin-mask').mask('000-00-0000', {placeholder: '___-__-____', reverse: true})
13-
$('.money-mask').mask('#.##0,00', {reverse: true})
14-
$('.percent-mask').mask('##0,00%', {reverse: true})
2+
const options = {
3+
onComplete: (v, e, f) => {
4+
// console.log('onComplete');
5+
f.addClass('valid')
6+
},
7+
onKeyPress: (v, e, f, options) => {
8+
if (!v) { return }
9+
//console.log('A key was pressed!:', v, ' event: ', e, 'currentField: ', currentField, ' options: ', options)
10+
//console.log('onKeyPress')
11+
f.removeClass('valid')
12+
f.addClass('glow-green')
13+
setTimeout(() => {
14+
f.removeClass('glow-green')
15+
}, 500)
16+
},
17+
// onChange: (v, e, f) => {
18+
// console.log('onChange');
19+
// },
20+
onInvalid: (v, e, f, invalid, options) => {
21+
if (!v) { return }
22+
//var error = invalid[0]
23+
//console.log('Digit: ', error.v, ' is invalid for the position: ', error.p, '. We expect something like: ', error.e)
24+
//console.log('onInvalid')
25+
f.removeClass('valid')
26+
f.addClass('glow-red')
27+
setTimeout(() => {
28+
f.removeClass('glow-red')
29+
}, 500)
30+
}
31+
}
32+
33+
$('.date-mask').mask('00/00/0000', {...options, placeholder: 'mm/dd/yyyy'}).keyup()
34+
$('.time-mask').mask('00:00:00', {...options, placeholder: 'hh:mm:ss'}).keyup()
35+
$('.datetime-mask').mask('00/00/0000 00:00:00', {...options, placeholder: 'mm/dd/yyyy hh:mm:ss'}).keyup()
36+
$('.cep-mask').mask('00000-000', {...options, placeholder: '_____-___'}).keyup()
37+
$('.zip-mask').mask('00000', {...options, placeholder: '_____'}).keyup()
38+
$('.phonebr-mask').mask('(00) 0000-0000', {...options, placeholder: '(__) ____-____'}).keyup()
39+
$('.phoneus-mask').mask('(000) 000-0000', {...options, placeholder: '(___) ___-____'}).keyup()
40+
$('.ip-mask').mask('099.099.099.099', {...options, placeholder: '___.___.___.___'}).keyup()
41+
$('.cnpj-mask').mask('00.000.000/0000-00', {...options, placeholder: '__.___.___/____-__', reverse: true}).keyup()
42+
$('.cpf-mask').mask('000.000.000-00', {...options, placeholder: '___.___.___-__', reverse: true}).keyup()
43+
$('.itin-mask').mask('000-00-0000', {...options, placeholder: '___-__-____', reverse: true}).keyup()
44+
$('.ssn-mask').mask('000-00-0000', {...options, placeholder: '___-__-____', reverse: true}).keyup()
45+
$('.money-mask').mask('#.##0,00', {...options, reverse: true}).keyup()
46+
$('.percent-mask').mask('##0,00%', {...options, reverse: true}).keyup()
1547
})(jQuery)

src/fields/MaskedField.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
use craft\base\PreviewableFieldInterface;
1616
use craft\fields\PlainText;
1717

18+
/**
19+
* @property-read null|string $settingsHtml
20+
*/
1821
class MaskedField extends PlainText implements PreviewableFieldInterface
1922
{
2023
// Public Methods
@@ -47,9 +50,10 @@ public function __construct(array $config = [])
4750
'zip' => 'Zip Code',
4851
'cep' => 'Cep',
4952
'ip' => 'IP',
53+
'itin' => 'ITIN',
54+
'ssn' => 'SSN',
5055
'cnpj' => 'CNPJ',
5156
'cpf' => 'CPF',
52-
'itin' => 'ITIN',
5357
];
5458

5559
parent::__construct($config);
@@ -90,7 +94,7 @@ public function getSettingsHtml(): ?string
9094
/**
9195
* @inheritdoc
9296
*/
93-
public function getInputHtml(mixed $value, ElementInterface $element = null): string
97+
public function getInputHtml(mixed $value, ?ElementInterface $element = null): string
9498
{
9599
$type = $this->type;
96100

0 commit comments

Comments
 (0)