AlpineJs dont update on binded property

856 Views Asked by At

I want to update property a binded (x-model) property on keydown.

But it does not work at all.

Do I something wrong here?

Link to jsfiddle

<div x-data="app()" class="w-64">
   <input x-ref="textInput" x-model="textInput" x-on:keyup="limitInput($el)" type="text">
</div>


function app() { 
  return {
    textInput: '',
    limitInput($el) {
       this.textinput =  ''
    },
   }
}
1

There are 1 best solutions below

4
Paul-Louis Mas On

You are limiting the length of the input to 0 using maxlength="0" this way nothing can be added inside the input.
Also, what are you trying to do with the limitInput function? because calling it on keydown will call it before the input is updated with the key pressed, if you want to call it after, use keyup.