Knockout-Contrib / Knockout-Contrib/Knockout-Validation
Allow params object without message property
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 1k
- Forks
- 366
- PR merge metrics
- No merged PRs in 30d
Description
When setting up validation, you can assign an value for comparison directly:
var myVal = ko.observable().extend({
minLength: 3,
});
Or you can assign an object if you want to customize the error message:
var myVal = ko.observable().extend({
minLength: {
params: 3,
message: "That is too short!"
},
});
I like to be consistent in how I set up my validation, regardless of whether I need to customize the message or not. So sometimes I'd like to do this (keeping the default error message):
var myVal = ko.observable().extend({
minLength: {
params: 3
},
});
But this doesn't work. ko validation compares the length of the value in my observable with { params: 3 } rather than comparing it with 3.
I suggest changing KO validation so that you can assign an object, such as my last example, even when there is no message property on that object.
If you like the idea I can work on a pull request.
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 by locating the validation setup code that distinguishes a direct parameter from an object containing params and message, then reproduce the minLength examples from the issue. Done means an object containing params without message compares against the inner value while retaining the default error message.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend
- Issue type
- Feature
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100