Knockout-Contrib / Knockout-Contrib/Knockout-Validation

Using Onlyif but dependant on the parent viewmodel?

Open
#658 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
1k
Forks
366
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

Open the contributing guide

Research direction

Start by tracing the `onlyIf` validation option from the child viewmodel example and reproduce the parent/child setup described in the issue. Check how the condition is evaluated when it references the parent viewmodel, then define completion as a confirmed supported behavior or a documented, tested correction for the reported case.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.