No one? :'(
Apr 7, 2022
6
Level 1
Livewire + Inputmask
Hi everyone! I'm not able to make Inputmask (RobinHerbots/Inputmask) working with livewire. Please I need help.
This is what I have inside app.js:
var Inputmask = require('inputmask');
The code above is working when I use input mask in "normal" blade pages.
This is my livewire blade page:
<div>
<form wire:submit.prevent="check">
<div class="mb-3">
<div class="col-12 col-md-6 col-lg-3">
<label for="code" class="form-label">{{ __('Customer code') }}</label>
<input type="text" class="form-control @error('code') is-invalid @enderror"
id="code" wire:model="code">
@error('code')
<small class="text-danger">{{ $message }}</small>
@enderror
</div>
@push('scripts')
<script>
Inputmask({
regex: "^\d{3}\.\d{3}\.\d{3}$",
placeholder: "_",
showMaskFocus: true,
showMaskOnHover: false,
clearIncomplete: true
}).mask(document.getElementById("code"));
</script>
@endpush
</div>
<button class="btn btn-primary">{{ __('Check') }}</button>
</form>
</div>
In the php part of livewire component I have the "check" function:
public function check(): void
{
dd($this->code);
}
The mask seems to work correctly on the page, but if I click on the "Check" button without Inputmask, I see the code; if I do this with Inputmask, the value is always "null".
I the developer console of my browser (Chrome) I see this error:
Uncaught TypeError: Cannot read properties of null (reading 'toString')
at c (inputmask.js?6e96:1559:1)
at HTMLInputElement.c (inputmask.js?6e96:2181:1)
at Object.setInputValue (dom.js:179:16)
at Object.setInputValueFromModel (dom.js:150:14)
at node_initializer.js:31:25
at Array.forEach (<anonymous>)
at Object.initialize (node_initializer.js:15:34)
at index.js:92:35
at index.js:525:17
at walk (walk.js:5:9)
Can you help me? Thanks!
Please or to participate in this conversation.