-
Notifications
You must be signed in to change notification settings - Fork 647
custom error messages not showing? #369
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
Comments
Ok, now this is interesting... I just got it working by using scope.$parent.$broadcast in one case, and scope.$parent.$parent.$broadcast in a different case. With a form looking like:
password-confirm uses $validators and needs 2x $parent. I would guess that the event listener is on the form scope? how can we broadcast to it from the custom validation? |
I think I would like it if I could do something like:
Seems to always set For now, I am using option 2 and in my formDefaults: { validationMessage: { "uniqueUsername": "Username is not unique" } } ... |
Hi @plong0, broadcasting the error message is for setting an error on a field from outside of schema form, not from inside. The way it works currently is that the name you give your asyncValidator gets used as it's error key, Edit: Changed |
Just a note, the problem your having with the events is just that it's meant to be a |
Hey, thanks for the clarity @davidlgj . I was suspecting that was the case... |
@plong0 I don't think its possible, I guess they designed asyncValidators to just do one validation :) From outside of schema form you can use the But you could probably hack something togheter by using a common service to do the actual call to the server, if they share the same promise then only one call is needed. |
Hmm, interesting... I thought setting a value in ngModel.$errors would do the trick... oh well. I thought of a way to refactor so it's no longer a problem. |
back with good news! An interesting thing I learned is that if you set multiple validationErrorKeys to false, it uses whichever one is set first. I also did a further test for if I ever want to set an error message on-the-fly (like from the server or otherwise dynamically generated by the validator)... then it is possible in a way like:
(I think if I ever did need that, I would encapsulate the dynamic error messages into a form.messages object or something like that) So that's pretty cool. I think that answered all my questions about how to generate and set error messages. |
I will add that if you are using
(I think this is a similar approach of how a-s-f is managing the custom tv4 errors) |
I've got a custom form directive with an async validator. The validation is working and setting the field valid/invalid depending on if the validation promise resolves or rejects.
Trouble I am having is with getting the error message to come through. I am using the code:
scope.$broadcast('schemaForm.error.'+ngModel.$name, 'unique', 'That thing is not unique!');
and to clear the error message:
scope.$broadcast('schemaForm.error.'+ngModel.$name, 'unique', true);
is this not the proper way to set the custom error message? I tried setting it in my formDefaults validationMessage,
"unique": "That thing is not unique"
and that works, but I would prefer to have the message coming from my validator.unique is the name of the $asyncValidators entry, which doesn't seem to make a difference.
The text was updated successfully, but these errors were encountered: