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

[Solved] Client Validation Issues & Fixes

4 Answers 191 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Tom
Top achievements
Rank 1
Tom asked on 22 Jan 2012, 11:25 PM
I've run in to two issues that will hopefully help others too

1) DataAnnotations don't create element attributes if model is null
There seems to be a different behavior between how MVC add's the data-validation attributes to an element and how Telerik controls do.  With telerik it seems that if a model (or sub model) is null the data validation attributes aren't included with the element.
Workaround
: Pass an empty model to your view:
return View(new RegisterModel());
//instead of
return View();


2) jQuery.validate.js v1.9.0 ignores hidden input fields used by ComboBox
The jQuery.Validation.Plugin version 1.9.0 has a change of behavior from 1.7 and by default ignores hidden elements.  You have to use a method to remove the ignore: ":hidden" property in order for it to work with Telerik.
Workaround:
// After jquery.validate.js is loaded
$.validator.defaults.ignore = [];

4 Answers, 1 is accepted

Sort by
0
Wicky
Top achievements
Rank 1
answered on 21 Feb 2012, 07:23 AM
Hi,
Your tips are helpful and valid for version 2012 Q1.
Thanks
Wicky
0
Dmitry
Top achievements
Rank 2
answered on 03 Apr 2012, 10:01 PM
Thank you!

it was very helpfull for me too. I have discovered at the end of the work day, what validation of Comboxes in the ajax-loaded partial views doesn't work.
Hope, can fix it before next testrelease :)
0
sta
Top achievements
Rank 1
answered on 28 May 2012, 09:23 PM
Tom,
does that solvers a validation problem with Telerik's ComboBox that doesn't do validation in razor environment in spite of all [Required] etc. on the viewmodel ?

Thanks
0
Jeff
Top achievements
Rank 1
answered on 20 Jun 2012, 01:15 PM

Hi Tom -

First - thank you!   Both of those tips are still very important and helped me out a lot.  

I'm not sure where you were calling your code to set the default ignore :hidden property.  I was finding that putting it in my regular $(document).ready() method was too late.   It was like the validators were already created for the form by the time my method was called, and setting the default value at that time didn't affect the form.  Maybe I just didn't put your code in the right place.  I was able to use your code in the _Layout file, directly after the script registrar, but I don't always have forms.  

I ended up doing something like this in my application's shared js file's $(document).ready() method.  I'm no jQuery expert, so there could be a simpler way to write this.   It seems to work though and fix the combobox validation issue with jQuery v1.9 on telerk Q2 2012.  


EDIT:  Clarified code location
$(document).ready(function () {
 
    ...
 
    $('form').each(function () {
        var validator = $(this).data('validator');
        if (validator && validator.settings) {
            validator.settings.ignore = [];
        }
    });
  
    ...
}

Thanks again, and just throwing another option out in case it's helpful to someone else.

Jeff

Tags
ComboBox
Asked by
Tom
Top achievements
Rank 1
Answers by
Wicky
Top achievements
Rank 1
Dmitry
Top achievements
Rank 2
sta
Top achievements
Rank 1
Jeff
Top achievements
Rank 1
Share this question
or