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

correct handle the 'params' arg #593

Closed
wants to merge 2 commits into from

Conversation

languanghao
Copy link

ko.intValue.extend({min:{
params: 3,
message: 'some messages'
}})

Above code won't work correct, because the code not correct handle the params, the 'min' validator get the params as a object, not the 'params' value 3.

ko.intValue.extend({min:{
   params: 3,
   message: 'some messages'
}})

Above code won't work correct, because the code not correct handle the params, the 'min' validator get the params as a object, not the 'params' value 3.
@crissdev
Copy link
Member

crissdev commented Dec 8, 2015

@languanghao Can you provide an example where the rule does not work? Thanks.


Working example http://jsfiddle.net/crissdev/9xqmrLs8/

@languanghao
Copy link
Author

@crissdev I have update the code.

The code below dose not work as excepted.

ko.field.extend({
  min: {
      params: 3
  }
});

I am writing a wtforms extentions with ko validation. In my code, I need to dynamic add validation rules to ko fields. My code like this:

var extend = {}
extend[ruleName] = {}
if (hasParams){
    extend[ruleName] = {'params': params}
else{
    extend[ruleName] = {'params': true}
}

I foud my problem was occurred because code of addExtender: function (ruleName) line 509 in knockout.validation.js. It seems like if a rule only have one params, you must write it as {ruleName: paramValue}, but not {ruleName: {params: paramValue}}.

@crissdev
Copy link
Member

crissdev commented Dec 9, 2015

Thanks for all the info. I believe this feature is already implemented in v2.1.0 branch. See #554 and #561.

Here's the updated example which uses the library from that branch http://jsfiddle.net/crissdev/9xqmrLs8/1/

@crissdev crissdev closed this Oct 5, 2019
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

Successfully merging this pull request may close these issues.

2 participants