Knockout-Validation
Knockout-Validation copied to clipboard
Using Onlyif but dependant on the parent viewmodel?
We have a parent/child viewmodel set up so that a parent record can have multiple child records. We need a validation rule on the child record that is only required when a field on the parent has a certain value.
Is this possible?
I've tried this in the child viewmodel:
required: { onlyIf: function () { return parent.FieldX() == Value; } }
Where parent
is the self
variable passed from the parent viewmodel to the child viewmodel. No errors generated, but this still doesn't work.