Validation fails but zero errors

1 Answer 38 Views
Validation
AP
Top achievements
Rank 1
Iron
Iron
Veteran
AP asked on 05 Jan 2024, 03:06 PM

I'm just migrating an application to ASP.NET Core. A couple of data forms in pop-up windows use a kendo validator. This works to validate fields and highlight required fields, but the validate function is returning false even though the error count is 0.

I'm using version v2023.3.1114 of Kendo UI for ASP.Net Core.

The validation code is:-

		var validator = $('#MetaDatafrm').kendoValidator({
			validationSummary: true,
			validate: function (e) {

				var dropDowns = $(".k-dropdown");

				$.each(dropDowns, function (key, value) {

					var input = $(value).find("input.k-invalid");

					var span = $(this).find("span.k-dropdown-wrap");

					if (input.length > 0) { //if there is an input in here with k-invalid...

						$(span).addClass("dropdown-validation-error");

					} else {

						$(span).removeClass("dropdown-validation-error");

					}

				});


			}
		}).getKendoValidator();

		var x = validator.validate();

		var errors = validator.errors();

		//alert(errors.length);

		if(errors.length==0)
		{
			x=true;
		}

		validator.showValidationSummary();

	

		if (x == false) {
			alert('Form has failed data validation. Please correct and try again');
			return;
		}

The form is loaded from a partial view loaded by:-

function editMetaData(rID, rs) {

	srcFilter=rs;

	var wind = $('#wndMetaDataEdit').data("kendoWindow");


	$('#btnSave').removeProp("disabled");
	 $('#errorMsg').hide();

	wind.refresh({
		url: "@Url.Content("~/Home/EditMetaData?reportID=")" + rID + "&src=" + rs 
		
	});
	wind.center();
	wind.open();



}

This code did work in a previous version (v2023.2.718) but that was ASP.NET MVC, not .Net core.

1 Answer, 1 is accepted

Sort by
0
Neli
Telerik team
answered on 10 Jan 2024, 11:42 AM

Hi Andrew,

In the provided snippet it seems that the used selectors are according the the old DropdownList rendering prior to R1 2022. I would suggest taking a look at the DropDownList backward compatibility and Old. vs. New sections where the changes in the rendering are described in more detail. 

With the above said, please try to change the used selectors according to the current rendering of the DropDownList component. Below is an example:

 var validator = $('#MetaDatafrm').kendoValidator({
          validationSummary: true,
          validate: function (e) {

            var dropDowns = $(".k-dropdownlist");            

            $.each(dropDowns, function (key, value) {
              var invalid = $(".k-dropdownlist.k-invalid");
              if (invalid.length > 0) { 
                alert('Invalid DropDownList')                
              } else {
                .....
              }
            });


          }
        }).getKendoValidator();

The above is demonstrated in the Dojo linked here - https://dojo.telerik.com/@NeliKondova/uzipExAK

I hope this helps. 

Regards,
Neli
Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages! Or perhaps, if you are new to our Kendo family, check out our getting started resources
AP
Top achievements
Rank 1
Iron
Iron
Veteran
commented on 10 Jan 2024, 12:25 PM

Neli,

Thanks. I've tried changing the selectors, but the issue still remains. Validation fires ok and the errors are highlighted correctly.  The problem is that once there are no errors, validation still returns false.

Neli
Telerik team
commented on 15 Jan 2024, 08:58 AM

Hi Andrew,

Could you please provide more details on how the issue can be replicated locally. I will appreciate it if you could preprae and send us small isolated runnable example where the issue is reproduced. You do not need to use existing database in the project, instead you can use dummy data.

Looking forward to your reply.

Regards,

Neli

Tags
Validation
Asked by
AP
Top achievements
Rank 1
Iron
Iron
Veteran
Answers by
Neli
Telerik team
Share this question
or