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

Returning error details instead only the error message in group.errors #226

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

delixfe
Copy link
Contributor

@delixfe delixfe commented Feb 8, 2013

I work currently in a project where we have the requirement to show all errors in a list.
errorDetails
The errors can come from several tabs. A click on a link (blue) opens the correct tab and focuses the corresponding input field.

knockout.validation currently does not support such scenarios because group only returns error messages as strings.

That pull requests extents knockout.validation.group to return error detail objects instead only strings.

That is enabled with a new configuration option: enableErrorDetails
If it is set to true then validateables will be extended with an property errorDetails which contains the following values:

if(configuration.enableErrorDetails) {
    // holds detailed error information  
    observable.errorDetails = {
        rule: ko.observable(null),
        params: ko.observable(null),
        observable: observable,
        message: ko.observable(null)
     };           
}

Setting enableErrorDetails to true also lets group.errors return an observable array of errorDetails objects instead of strings. That gives the power to build more complex error lists.

The changeable properties of errorDetails are knockout observables. That solves the problem that the errors of the result of validation.group are not correctly updated if only the type of the error changes, e.g. going from a required to a minimum length error (as described in #218).

delixfe added 12 commits June 27, 2012 15:28
which does not only contain the message but also the rule,
the params and the observable itself (to have access to it on grouping).
If errorDetails is truthy then errorDetails objects are returned instead of plain error messages.
Conflicts:
	Src/knockout.validation.js
	Tests/validation-tests.js
Conflicts:
	Src/knockout.validation.js
because otherwise the call to observable.__valid__(isValid) triggers the reevaluation of computeds
before errorDetails is written.
To solve the problem of going from one invalid state to the next not updating lists bound to errorDetails.
@dealproc
Copy link

cool. hoping that script# and typescript get updates to reflect this as well.

hoping as changes like this are done, those that are doing the change are thumbing out how you'd do it from JavaScript generators, as well as virgin JavaScript.

will you be providing examples for the scenarios this was built for @delixfe ?? especially how you bound to the right tab set?

@kiaplayer
Copy link

@delixfe: Thanks. But why so many commits? Please, use "git rebase" or "git commit --amend" next time.

@dsample
Copy link

dsample commented May 28, 2013

Any movement on this? We've taken this patch into our project to see how it works and it's much better than the basic string array, although even with the field's observable available to us it's still hard to find the field name.

We're trying to do exactly the same thing as @delixfe has created the patch for, posting the validation errors at the top of the page to guide the user. @delixfe do you have some example code for your scenario of how you get the field name and shortened error text?

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.

4 participants