Knockout-Contrib / Knockout-Contrib/Knockout-Validation
Resetting model and Async rules and Required
- Dominant language
- JavaScript
- Stars
- 1k
- Forks
- 366
- PR merge metrics
- No merged PRs in 30d
Description
I have a property where I have a Async rule on and a Required rule. I don't want the "error tile" to show right away in the UI until the user "touches" the field (enters, modifies, data, etc).
I tried using showAllMessages to reset my properties. However, this won't fix the problem because the required rule is already failed (if the field is empty). What happens is isModified changes, and then my "error tile" binder will flash until the async rule is complete.
isValidating is not helpful, because isValidating is not set to true, until after my error tile flashes because of isModified changed before isValidating is set to true.
If everyone is in agreement, I think the real solution in these cases is to "reset" your properties completely. Obviously manually iterating over every property to call clearError is not the greatest solution.
So could we add this to the source (under the group method right below result.showAllMessages?
```
result.clearAllErrors = function () {
// ensure we have latest changes
result();
forEach(context.validatables, function (observable) {
observable.clearError();
});
};
```
If anyone wanted to put this into the branch I would be extremely happy... Unless, there is a better solution to my problem.
Contributor guide
Research direction
Start in the source's group method near result.showAllMessages and inspect how context.validatables and observable.clearError are used. Add the proposed result.clearAllErrors behavior, ensuring it refreshes the result and clears each validation error; done means callers can reset all properties without manually iterating over them.
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
- Clearly specified
- Newbie friendliness
- 45/100