javascript - How to highlight a checked radio button using jquery validate highlight property -


i trying add new functionality written other guy, need highlight radio button after validation on 1 of grid element in same row radio butotn.

$.validator.addmethod(      "countycheck",      function (value, element) {                           if ($("input[type='radio']:checked").closest('tr').find('select') && $("input[type='radio']:checked").closest('tr').find('select').length > 0) {                  if ($("input[type='radio']:checked").closest('tr').find('select').val() != '')                      return ($.trim($('#tobevalidated').val()).tolowercase() === $.trim($("input[type='radio']:checked").closest('tr').find('select').val()).tolowercase());                  else                      return true;              }              else {                  return ($.trim($('#tobevalidated').val()).tolowercase() === $.trim($("input[type='radio']:checked").closest('tr').find('.labelclass').html()).tolowercase());              }                }, ""); 

the above validation method checks radio buttons in grid , searches drop down list(if 1 exists) or label , checks if selected option/label value equal value validated.(#tobevalidated). cshtml grid looks thing this:

var grid = addresses != null ? new webgrid(addresses, cansort: false, canpage: false) : new webgrid(new list<address>(), cansort: false, canpage: false); var gridcolumns = new list<webgridcolumn>();  gridcolumns.add(grid.column("", format: item => html.radiobutton("isstandardized", true, ((bool?)item.isstandardized).getvalueordefault(), new { data_serializedaddressdata = (string)item.jsonserializedaddressdata }), style: "webgridcol1width")); gridcolumns.add(grid.column("address1", "address1", style: "addrline")); gridcolumns.add(grid.column("address2", "address2", style: "addrline")); gridcolumns.add(grid.column("city", "city", style: "webgridcol2width")); gridcolumns.add(grid.column("state", "state", style: "webgridcol2width")); gridcolumns.add(grid.column(header: "postal code", style: "webgridcol2width", format: item => commonutility.getzipcode((address)item.value, true))); gridcolumns.add(grid.column("country", "country", style: "webgridcol2width")); //todo: need see how add addresstype standardized addresses or check updated address' addresstype if (updatedaddresses.any(addr => !(addr.addresstype == addresscodeenum.billingaddress || addr.addresstype == addresscodeenum.mailingaddress))) {     gridcolumns.add(grid.column(columnname: "county", header: "county", style: "countyname", format: addr =>        {            if (addr.standardizedcounties != null && addr.standardizedcounties.count > 1)            {                bool isradioselected = ((bool?)addr.isstandardized).getvalueordefault();                list<selectlistitem> countieslist = html.converttoselectlist<string>((list<string>)addr.standardizedcounties, (a) => a, (a) => a, true, isradioselected ? model.standardizedaddress.county : "");                mvchtmlstring returnvalue = html.dropdownlist((string)string.format("countyddl[{0}]", addr.webgrid.rows.indexof(addr)), countieslist);                return returnvalue;            }            else            {                string county = (addr.standardizedcounties != null && addr.standardizedcounties.count == 1) ? model.county : addr.county;                return county;            }        })); } 

i want highlight checked radio button when validation fails, problem jquery-validate.js

highlight: function(element, errorclass, validclass) {         if (element.type === 'radio') {             this.findbyname(element.name).addclass(errorclass).removeclass(validclass);         } else {             $(element).addclass(errorclass).removeclass(validclass);         }     } 

uses add css class, since element.name in same radio buttons, want highlight button checked.

i used in highlight method of validate.js

highlight: function(element, errorclass, validclass) {         if (element.type === 'radio') {             $(element).is(":checked").addclass(errorclass).removeclass(validclass);         } else {             $(element).addclass(errorclass).removeclass(validclass);         }     }, 

but not seem work , more on reloads page whenever validation fired.

i nub @ , if 1 point me in right direction, of great help. thanks!


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 -