Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parent/Child validation rule of child onlyIf from parent in large dataset #678

Open
abbottmw opened this issue May 7, 2021 · 0 comments

Comments

@abbottmw
Copy link

abbottmw commented May 7, 2021

I have a viewmodel with a parent/child, and the child has a property with a required rule. the required rule has an onlyIf which needs to look at a parent property.

in my parent vm I have a fooParent observable equal to true or false. This is updated in the UI via a dropdown.

in my child vm fooChild I need to set the onlyIf required part based on the fooParent observable.

it all works great for small data sets, but large datasets the UI will freeze when the dropdown is changed.

Is there a way to add a required onlyIf to a child property without it freezing or locking up the UI as it builds the validation rules for each child?

Could I add the rules to the children from the parent vm or would I run into an issue with any new children that are added later through the UI not having the rule applied.

==

pseudo code.. typing from my head to try and provide a small example. this in the real world the child array would be mapped to the array coming in. the key thing is the onlyIf: in the fooChild rule.

var parentvm = function() {
     var self = this;
    self.fooParent = ko.observable(false);
    //there will be 200+ children mapped here.
    self.Children = ko.observableArray( [  new childvm(self) ]);
}

var childvm = function(parent) {
    var self = this;
   var fooChild = ko.observable().extend({   required: {  ... onlyIf: function() { return parent.fooParent() } }  })
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant