javascript - Make field not required based to dropdown list selection MVC 5 -


in mvc 5 app, have form dropdown , fields required. need change attribute of fields when dropdown selection change.

i have enum

public enum orderkind {      market,     research,  } 

from fill dropdown list. have use javascript show or hide fields work.

something as

 $(function () {    $('#orderkind').change(function () {             var value = $(this).val();             if (value == "market") {                 $(datefrom).hide();                 $(datefrom).hide();                 $("#fromdate").attr("required", false);                 $("#todate").attr("required", false);     else if (value == "research") {                 $(datefrom).show();                 $(datefrom).show();                 $("#fromdate").attr("required", true);                 $("#todate").attr("required", true);                 fromdate.setcustomvalidity('please fill date field');                 todate.setcustomvalidity('please fill date field');           } 

but makes date fields required, when filled displays message. there way check dropdown list value controller? thank you!

i think have change enum to

public enum orderkind {     market = 1,     research = 2, } 

then, bind value drop down list , add external (default) value it.


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -