Reputation: 2301
I have an input field like so:
<input type="text" @input=readInput('usernameInput')>
And data and method:
data() {
return {
usernameInput = false;
};
},
readInput(form) {
console.log(form); //usernameInput
}
So anytime a user enters a character in the input
field, the readInput
method is activated with the word 'usernameInput' passed to it.
But I am trying to do something like this:
readInput(form) {
this.form = true;
}
Basically, when someone enters anything into the input field, I want usernameInput
to change to true
. So I want that this.form
to really be equal to this.usernameInput
. Is there a way I can go about accomplishing this?
Please note: this is a simple example; I am aware I can just do this.usernameInput = true
, but I am trying to create a more general method.
Upvotes: 0
Views: 32
Reputation: 50787
<input type="text" name="usernameInput" @input="readInput($event, true)"/>
Now your method has access to the event, and passes true:
readInput(e, flag) {
this[e.target.name] = flag
}
A more dynamic and generic solution for you.
Upvotes: 1