Knockout-Contrib / Knockout-Contrib/Knockout-Validation
Pattern validation fails when the message is an empty string
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 1k
- Forks
- 366
- PR merge metrics
- No merged PRs in 30d
Description
When specifying the pattern binding, and the message is empty:
this.value.extend({
pattern: { params: Constants.NAME_REGEX, message: "" }
});
Then in addExtenders call the wrong addRule method will be invoked, and upon processing of the pattern validation, it will not use the regular expression, but the actual params object, which will not work so well.
if (params && (params.message || params.onlyIf)) { //if it has a message or condition object, then its an object literal to use
return kv.addRule(observable, {
rule: ruleName,
message: params.message,
params: utils.isEmptyVal(params.params) ? true : params.params,
condition: params.onlyIf
});
} else {
Suggested fix:
if (params && (params.message !== undefined || params.onlyIf !== undefined)) { //if it has a message or condition object, then its an object literal to use
return kv.addRule(observable, {
rule: ruleName,
message: params.message,
params: utils.isEmptyVal(params.params) ? true : params.params,
condition: params.onlyIf
});
} else {
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at addExtenders and inspect the branch that handles pattern parameters with an empty message. Verify the empty message is treated as a defined option while the regular expression remains the rule parameters, then confirm pattern validation works with message: "".
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100