V
V
VegasChickiChicki2019-10-08 13:36:27
JavaScript
VegasChickiChicki, 2019-10-08 13:36:27

How not to assign a class if the value of the variable is null?

The bottom line is this, I have a form and input fields in it, after the user removes focus from the input field, I need to check it and change the value of the corresponding field in data, for example form.name = false. I will return false if the fields are not filled in correctly, and based on these variables, I need to assign a class, class 2, to an error and to a correct input, but as long as the user has not touched the fields, there should be no classes.
Now I tried to do it like this:

:class="form.FirstName ? 'input-successes' : 'input-error'"
//даже так
v-bind:class="{ 'input-successes': form.FirstName, 'input-error': !form.FirstName, '':  form.FirstName === null }"

But something always equals null to false, I don’t know how to fix it, please help, thanks!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2019-10-08
@VegasChickiChicki

:class="form.FirstName !== null ? form.FirstName ? 'input-successes' : 'input-error' : ''"

or
or
or
It would be better to wrap this, of course, in a computed / method, somehow it turns out cumbersome.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question