Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Masked input with imask.js #118

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion resources/views/components/input.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
</span>
@endif
<div class="relative w-full">

<input
@if($field->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 ]) }}
/>
@error($field->key)
Expand All @@ -43,3 +43,8 @@
</span>
@endif
</div>
@if($field->maskOptions)
@tfonce('scripts:imask')
<script src="https://unpkg.com/imask"></script>
@endtfonce
@endif
1 change: 1 addition & 0 deletions src/Components/Input.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ protected function defaults(): array
'min' => 0,
'max' => null,
'disabled' => false,
'maskOptions' => ''
];
}

Expand Down
10 changes: 10 additions & 0 deletions src/Input.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class Input extends BaseField
public $sfxTallIcon;
public $sfxHtmlIcon;
public bool $sfxHasIcon = false;
public string $maskOptions = '';

protected function overrides(): self
{
Expand Down Expand Up @@ -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;
}

}