I have a form where I make a call to the server and it gives me an array of errors that contains the key of the field and the message. How can I simply show these messages through the validation widget?
Something like:
validator.AddError("Subject","My custom error from server");
Something like:
validator.AddError("Subject","My custom error from server");
10 Answers, 1 is accepted
0
Hi Jonathan,
I am not sure if I understood your scenario correctly. Generally speaking I you can customize the validation messages through the validator configuration and / or create a custom validation rules, however the validator does not have an AddError method.
Could you please take a look at this example and let me know if I missed something?
Kind regards,
Alexander Valchev
the Telerik team
I am not sure if I understood your scenario correctly. Generally speaking I you can customize the validation messages through the validator configuration and / or create a custom validation rules, however the validator does not have an AddError method.
Could you please take a look at this example and let me know if I missed something?
Kind regards,
Alexander Valchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Jonathan
Top achievements
Rank 1
answered on 07 Jun 2012, 02:53 PM
Well so how do I add multiple custom messages from the server? So if there are additional fields each with their own customer error message. Here is the updated example http://jsfiddle.net/Lbc5a/
0
Hello Jonathan,
Basically the approach for adding multiple messages is identical to the previous one:
For convenience I have updated the Fiddle, please check the result.
Greetings,
Alexander Valchev
the Telerik team
Basically the approach for adding multiple messages is identical to the previous one:
//JSON returned from the server
{
"required"
:
"My custom required message"
,
"anotherCustom"
:
"Only John Doe can book a ticket"
,
"email"
:
"That's a wrong email!"
,
"custom"
:
"You are not John!"
}
//validator set up
validator = $(
"#tickets"
).kendoValidator({
rules: {
custom:
function
(input) {
//...
},
anotherCustom:
function
(input) {
//...
}
},
messages: myMessages
}).data(
"kendoValidator"
);
For convenience I have updated the Fiddle, please check the result.
Greetings,
Alexander Valchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Jonathan
Top achievements
Rank 1
answered on 16 Jun 2012, 03:19 AM
I see how that works but i am really looking for something even simpler than that. Because on the client side I might not know the rules to define, I just know I am getting back a list of messages that contain the Field name and the message for the error. So I can't define the rules portion of that example. So it has to be a little more dynamic. Or it really just needs to be as simple as:
validator.addError(FieldName, ErrorMessage);
I have used validation frameworks in the past that were pretty much that simple. Understand the rules setup but seems in cases like this I need something super simple.
validator.addError(FieldName, ErrorMessage);
I have used validation frameworks in the past that were pretty much that simple. Understand the rules setup but seems in cases like this I need something super simple.
0
Hi Jonathan,
The validator does not have an addError method as the one you are looking for, so if I understood it correctly your scenario is not supported.
Regards,
Alexander Valchev
the Telerik team
The validator does not have an addError method as the one you are looking for, so if I understood it correctly your scenario is not supported.
Regards,
Alexander Valchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Jonathan
Top achievements
Rank 1
answered on 27 Jun 2012, 08:48 PM
Ok I a managed to make it work, you can see the code below:
I also updated the jsfiddle example. http://jsfiddle.net/Lbc5a/33/
var
validator;
$.ajax({
//using jsfiddle echo service to simulate JSON endpoint
url:
"/echo/json/"
,
dataType:
"json"
,
type:
"POST"
,
data: {
// /echo/json/ echoes the JSON which you pass as an argument
json: JSON.stringify(
{
email:
"That's a wrong email!"
,
FirstName:
"No johns allowed."
,
email:
"Only John Doe can book a ticket this is email validation"
}
)
},
success:
function
(response) {
var
myMessages = response;
var
myRules =
new
Object();
for
(
var
messageName
in
myMessages)
{
myRules[messageName] =
function
(input) {
if
(input[0].id == myMessages[input[0].id])
{
return
false
;
}
};
}
validator = $(
"#tickets"
).kendoValidator({
rules:myRules,
messages: myMessages
}).data(
"kendoValidator"
);
var
status = $(
".status"
);
$(
"button"
).click(
function
() {
if
(validator.validate()) {
status.text(
"Hooray! Your tickets has been booked!"
).addClass(
"valid"
);
}
else
{
status.text(
"Oops! There is invalid data in the form."
).addClass(
"invalid"
);
}
});
}
});
I also updated the jsfiddle example. http://jsfiddle.net/Lbc5a/33/
0
Jonathan
Top achievements
Rank 1
answered on 27 Jun 2012, 09:12 PM
Wait that didn't work but it is closer. Any ideas? Right now it is throwing more validation errors on things that don't have validation.
0
Jonathan
Top achievements
Rank 1
answered on 27 Jun 2012, 10:10 PM
I have updated the jsfiddler to my current attempt to pull off what I need. But the issue now is that it shows the same error message for every field that has an error and doesn't base it on the name of the rule. I am so close to getting this.
Any ideas?
Any ideas?
0
sri
Top achievements
Rank 1
answered on 18 Apr 2014, 02:25 AM
Hi, I am working on the same issue as you had posted sometime back. Did you get the custom validation messages to display at the respective input fields dynamically? Please provide your solution if possible. Thanks.
-1
Hello Sri,
This topic is about two years old. My recommendation is to check the following help articles as they contain accurate information and code samples which you can run and test on your side (all you need to do is to put them in a HTML page with Kendo UI included).
Please check the help topics and open a new forum thread in case you have any further questions. We will appreciate if you provide the needed details in it (sample/code) so we can spot the issue faster and assist you accordingly.
Regards,
Alexander Valchev
Telerik
This topic is about two years old. My recommendation is to check the following help articles as they contain accurate information and code samples which you can run and test on your side (all you need to do is to put them in a HTML page with Kendo UI included).
- http://docs.telerik.com/kendo-ui/getting-started/framework/validator/overview#custom-validation-rules
- http://docs.telerik.com/kendo-ui/getting-started/framework/validator/overview#error-messages
Please check the help topics and open a new forum thread in case you have any further questions. We will appreciate if you provide the needed details in it (sample/code) so we can spot the issue faster and assist you accordingly.
Regards,
Alexander Valchev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!