Skip to content

Rules are added multiple times when options.parseInputAttributes and options.writeInputAttributes are both set to true. #277

@benpriebe

Description

@benpriebe

When the parseInputAttributes and writeInputAttributes options are set to true; the writeInputAttributes occurs first; then the parseInputAttributes comes along after and says hey, there's some input attributes that i should go create rules for - even though we already have the rule.

See fiddle for verification:
http://jsfiddle.net/t2y5F/

Suggestion:

Modify addRule() function to check the rule isn't there already. Something like:

 addRule: function(observable, rule) {
                if (!utils.isValidatable(observable))
                    observable.extend({ validatable: true });

                var hasRule;
                ko.utils.arrayForEach(observable.rules(), function(arrRule) {
                    if (arrRule.name == rule.name) {
                        hasRule = true;
                        return;
                    }
                });

                if (!hasRule) {
                    //push a Rule Context to the observables local array of Rule Contexts
                    observable.rules.push(rule);
                }
                return observable;
            },

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions