From 4894149c212696e17f56b1581e8bf303b75cca1b Mon Sep 17 00:00:00 2001 From: simonbuehler Date: Sat, 19 Feb 2022 17:34:51 +0100 Subject: [PATCH 1/5] add imask.js masking options to input field (cherry picked from commit 20d449e5927e9aa6fec167931cce744f9973df01) --- resources/views/components/input.blade.php | 7 ++++++- src/Components/Input.php | 1 + src/Input.php | 10 ++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/resources/views/components/input.blade.php b/resources/views/components/input.blade.php index 440c912..c734b66 100644 --- a/resources/views/components/input.blade.php +++ b/resources/views/components/input.blade.php @@ -1,4 +1,4 @@ -
only('x-data') }} class="{{$field->wrapperClass}}"> +
maskOptions) x-data @endif class="{{$field->wrapperClass}}"> @if($field->prefix || $field->hasIcon) @if($field->icon) @@ -19,6 +19,7 @@ @unless($field->disabled) required) required @endif + @if($field->maskOptions) x-ref="imaskref" x-init="$nextTick(() => IMask($refs.imaskref, {{$field->maskOptions}} ))" @endif {{ $attributes->except([...array_keys($attr), 'x-data', 'required', 'disabled'])->merge($attr)->merge(['class' => $errors->has($field->key) ? $field->errorClass : $field->class ]) }} /> @else @@ -45,3 +46,7 @@ @endif
+@tfonce('scripts:imask') + +@endtfonce + diff --git a/src/Components/Input.php b/src/Components/Input.php index c7c7238..0c416bb 100644 --- a/src/Components/Input.php +++ b/src/Components/Input.php @@ -53,6 +53,7 @@ protected function defaults(): array 'min' => 0, 'max' => null, 'disabled' => false, + 'maskOptions' => '' ]; } diff --git a/src/Input.php b/src/Input.php index fb2e95b..1ebf4bd 100644 --- a/src/Input.php +++ b/src/Input.php @@ -25,6 +25,7 @@ class Input extends BaseField public $sfxTallIcon; public $sfxHtmlIcon; public bool $sfxHasIcon = false; + public string $maskOptions = ''; protected function overrides(): self { @@ -143,5 +144,14 @@ public function suffixHtmlIcon(string $html): self $this->sfxHasIcon = true; return $this; } + /** + * @param string $mask_options + * @return $this + */ + public function maskOptions(string $mask_options): self + { + $this->maskOptions = $mask_options; + return $this; + } } From 8c232cd4d956cd1b3c3d8c704215fc9e8c564dad Mon Sep 17 00:00:00 2001 From: simonbuehler Date: Tue, 22 Feb 2022 14:46:51 +0100 Subject: [PATCH 2/5] only require js when maskOptions are used should fix the unneeded js load (cherry picked from commit 19dcea6fa9cde39576b1f6aace73ae79439ffc6e) --- resources/views/components/input.blade.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/resources/views/components/input.blade.php b/resources/views/components/input.blade.php index c734b66..b721c81 100644 --- a/resources/views/components/input.blade.php +++ b/resources/views/components/input.blade.php @@ -46,7 +46,9 @@ @endif
-@tfonce('scripts:imask') - -@endtfonce +@if($field->maskOptions) + @tfonce('scripts:imask') + + @endtfonce +@endif From a9bc3231e7fb33c1d7c213cb8e9d56f11dca710a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20B=C3=BChler?= Date: Mon, 28 Mar 2022 14:48:33 +0200 Subject: [PATCH 3/5] revert x-data handling (cherry picked from commit b741c054020d63d65ae5d9ab38c48326b97efccb) --- resources/views/components/input.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/components/input.blade.php b/resources/views/components/input.blade.php index b721c81..ad1e622 100644 --- a/resources/views/components/input.blade.php +++ b/resources/views/components/input.blade.php @@ -1,4 +1,4 @@ -
maskOptions) x-data @endif class="{{$field->wrapperClass}}"> +
only('x-data') }} class="{{$field->wrapperClass}}"> @if($field->prefix || $field->hasIcon) @if($field->icon) From 5a2e4f782c3e6dbef484bcf7602e9aacea638234 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20B=C3=BChler?= Date: Mon, 28 Mar 2022 15:21:43 +0200 Subject: [PATCH 4/5] fix merge conflict --- resources/views/components/input.blade.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/resources/views/components/input.blade.php b/resources/views/components/input.blade.php index 330e0e3..a7732d4 100644 --- a/resources/views/components/input.blade.php +++ b/resources/views/components/input.blade.php @@ -16,16 +16,12 @@ @endif
- required) required @endif @if($field->disabled) disabled @endif @if($field->maskOptions) x-ref="imaskref" x-init="$nextTick(() => IMask($refs.imaskref, {{$field->maskOptions}} ))" @endif {{ $attributes->except([...array_keys($attr), 'x-data', 'required', 'disabled'])->merge($attr)->merge(['class' => $errors->has($field->key) ? $field->errorClass : $field->class ]) }} /> - @else - - @endunless @error($field->key) @enderror From 1fd85702eb2d302be4ddc0f731f53c13dcfc328b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20B=C3=BChler?= Date: Mon, 28 Mar 2022 15:25:53 +0200 Subject: [PATCH 5/5] re-add js deps --- resources/views/components/input.blade.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/resources/views/components/input.blade.php b/resources/views/components/input.blade.php index a7732d4..dbd82fa 100644 --- a/resources/views/components/input.blade.php +++ b/resources/views/components/input.blade.php @@ -43,3 +43,8 @@ @endif
+@if($field->maskOptions) + @tfonce('scripts:imask') + + @endtfonce +@endif