jquery - validate not work when use javascript -


when use in view

<select data-val="true" data-val-required="Выберете" значение=""   id="directionside" name="directionside"><option value=""></option> <option value="27b8c509-8f09-4a0d-ae22-048c2611b7ea">По ходу движения </option> <option value="f40319b8-aa82-4182-bec2-4c9b0ba0146d">Против хода движения</option> <option value="7436112a-122c-4809-9f6c-c5aefff17d6d">На центр перекрестка</option> <option value="266ea166-67e8-446b-95b1-288b0b876eed">Вращается</option> </select> 

this work when put in of javascript-it not work example

$("#insertphoto").before("...."); 

any ideas ?

when put in of javascript-it not work

that's because .validate() method has been called , plugin initialized. (if you're using unobtrusive-validation along asp, unobtrusive plugin has called .validate() you.) if select did not exist when .validate() called, cannot expect plugin know it.

if you're going dynamically create new elements after page loaded (and after .validate() called), must use the .rules('add') method.

$("#insertphoto").before("...."); // <- code  $('select[name="directionside"]').rules('add', {     required: true }); 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -