Looking to assign a class to an inbox item in Vue when the value is equal to 'null'. I have almost achieved this, but there's one aspect I can't figure out. I've been following examples like https://v2.vuejs.org/v2/guide/class-and-style.html, but I have some specific requirements. I need to dynamically define a class based on the computed property value nested within my form. I have a form with multiple input fields (generated using v-for), and I should check each field's value and apply a specific class if certain conditions are met. I can achieve this initially, but struggling to update the class as the user changes the input values.
This is an example of the loop:
<div
class="form__field form__field--autocomplete"
v-for="input in info"
:key="input.PARAMETER_NAME"
v-if="input.PARAMETER_NAME != 'p_euser' && input.PARAMETER_NAME != 'p_dbuser_password'"
>
Here is an example of one particular field type based on the input.DATA_TYPE:
<input
v-else-if="input.DATA_TYPE == 'smallint' || input.DATA_TYPE == 'int'"
v-model="recordComputed[input.PARAMETER_NAME]"
type="number"
class="form__field-input"
v-bind:class="['', { 'nullclass' : [recordComputed[input.PARAMETER_NAME=='null']] }]"
:disabled="input.i2_primary_key == '1' && method == 'edit'"
>
The recordComputed object is the main object (computed property) defined like this:
recordComputed: {
get () {
let record = this.record
this.info.forEach((input) => {
var parValue = this.selected[input.i2_header_db]
// if we do not have parValue and it is typeof=='object', we set it as null
if (!parValue && typeof (parValue) === 'object') {
parValue = 'null'
}
record[input.PARAMETER_NAME] = parValue
})
return record
},
My question is whether it's possible to read the value from a computed property reactively – specifically, one of its keys – in order to dynamically change the class for a specific input field. If there are alternative approaches, I'm open to suggestions.