lundi 6 septembre 2021

How to get the correct syntax of v-model to be passed as a condition in if-else

How to utilize the v-model="item.checked" as the condition of the if in below validations()?

<tr>
    <div>
        <td>
            <input type="checkbox" v-model="item.checked" :id="'disable-'+i" v-on:click="disable(i)"/>
        </td>
        <td>
            <input type="text" :id="'total_hour-'+i">
        </td>
    </div>
</tr>

<script>
    import { required, minLength } from "vuelidate/lib/validators";
    export default {
        data() {
            return {
                checked: false,
                timesheet: { items: [{ total_hour: "", checked: false }] },
            }
        },
        validations() {
            if (...) {
                return{
                    timesheet: {
                        items: {
                            required,
                            minLength: minLength(1),
                            $each: { total_hour: {required} }
                        }
                    }
                }
            } else {
                return{
                    timesheet: {
                        items: {
                            required,
                            minLength: minLength(1),
                            $each: { total_hour: {} }
                        }
                    }
                }
            }
        }
    }
</script>

Aucun commentaire:

Enregistrer un commentaire