Javascript/jQuery: Get specific elements from form -
i have extense form around 25 inputs (text, radio , checkboxes). want when click button opens jquery dialog, loads form , set fields except 5 of them disabled. seems easy, want "generic" function. mean, have method:
function disableinputs(jqueryelement, exceptions, booleanclean) { //some stuff } i want inputs jqueryelement, ignoring elements ids have exceptions. exceptions object one:
var exceptions = { 0: 'clientid', 1: 'clientname', 2: 'clientfirstsurname', 3: 'clientsecondsurname', 4: 'clientalias' } this full code , i've tested, way make work and, if have recieved third parameter (booleanclean), set value='' inputs, instead elements weren't excluded being disabled. boolean works check if want clean inputs when function called:
function disableinputs(jqueryelement, exceptions, booleanclean) { var inputs = jqueryelement.find('input'); (var = 0; < inputs.length; i++) { inputs[i].setattribute('disabled', true); (var attr in exceptions) { if (inputs[i].getattribute('id') === exceptions[attr]) { inputs[i].removeattribute('disabled'); } else { if (booleanclean === true) { inputs[i].value = null; } } } } } i know why not working clean "option". want have put or if can set condition when inputs inputs not excluded (preferible second option optimization , not set attribute each input , remove them if excluded. seems easier work).
try
function disableinputs(jqueryelement, exceptions, booleanclean) { var not = jquery.map(exceptions, function(item, index){ return '#' + item; }).join(',') var inputs = jqueryelement.find(':input').not(not).prop('disabled', true); if(booleanclean){ inputs.val('') } }
Comments
Post a Comment