This is a migrated thread and some comments may be shown as answers.

custom rule message not being added to errors collection

1 Answer 34 Views
Validation
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 2
Chris asked on 22 Oct 2015, 10:11 AM

Hi,

I have a custom rule that check to see if a grid has any rows when a certain check is checked. The rule works correctly (that is it prevents submission if it is not met and allows if it is met), but the defined message is never added to the errors collection and therefore not displayed on screen. The other two custom rule /  messages work as intended and display correctly.

I am using the Q2 2015 professional version in an MVC 4 web app with bootstrap.

 

Here is the validator configuration, which is contained within a standard  jQuery 'document.ready' function:

01.jQuery("#HAForm").kendoValidator({
02.               rules: {
03.                   pupilSelected: function (input) {
04.                       if (input.is("#pupilSelector [type=checkbox]")) {
05.                           return jQuery("#pupilSelector input:checked").length > 0;
06.                       }
07. 
08.                       return true;
09.                   },
10.                   travelOptionSelected: function (input) {
11.                       if (input.is("#travelOptions [type=checkbox]")) {
12.                           return jQuery("#travelOptions input:checked").length > 0;
13.                       }
14. 
15.                       return true;
16.                   },
17.                   flightsAdded: function (input) {
18.                       if (input.is("#travelOptions input:checked[value='Flying']")) {
19.                           return jQuery("#flightGrid").data("kendoGrid").tbody.find('>tr').length > 0;
20.                       }
21. 
22.                       return true;
23.                   }
24.               },
25.               messages: {
26.                   pupilSelected: "You must choose at least one pupil.",
27.                   travelOptionSelected: "You must choose at least one travel option.",
28.                   flightsAdded: "You must add at least one flight."
29.               },
30.               validate: function () {
31.                   showErrors(this.errors());
32.               }
33.           });

 

And this is the code that displays the errors on screen:

01.function showErrors(errors) {
02.           var errorsContainer = jQuery("#errors");
03.           var html = "";
04. 
05.           for (var idx = 0; idx < errors.length; idx++) {
06.               html += "<li>" + errors[idx] + "</li>";
07.           }
08. 
09.           errorsContainer.empty().append(jQuery(html));
10.       }

 

I am at a loss as to why the first two messages display correctly but the 'flightsAdded' message is never displayed even when it is the only rule. 

Thanks

Chris

 

1 Answer, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 26 Oct 2015, 07:52 AM

Hello Chris,

 

Unfortunately, I'm not sure what is the cause for the issue you have described judging by the provided information. Could you please provide a small runnable sample which demonstrates the issue in question. 

 

Regards,
Rosen
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Validation
Asked by
Chris
Top achievements
Rank 2
Answers by
Rosen
Telerik team
Share this question
or