Código Javascript:
Ver original
var newparameterform = $('#NewParameterUnitForm').validate({ onfocusout: function(element){ $(element).valid();}, onsubmit: true, rules: { ParameterSelect: { required: '#ValueNewParameter:not(:visible)', remote: { url: '../request/checkrepeated/', type: 'POST', cache: false, data: { from: function(){return $('#FromOrigin').val();}, name: function(){return $('#ParameterSelect option:selected').text();}, value: function(){return $('#ParameterSelect option:selected').val();}, request: function(){return $('#IdRequest').val();}, x: function(){return $('#IdUnit').val();}, options: function(){ var myarray = []; var i = 0; if(String($('#FromOrigin').val()) !== 'detail'){ $('#RequestTechnicalParameter tbody tr:nth-child('+ $('#RowOrigin').val() +')').find('.parameter-title').each(function(){ myarray[i] = $(this).text(); i++ }); } return JSON.stringify( myarray ); } } } }, ValueNewParameter: { required: '#ValueNewParameter:visible', remote: { url: "../request/checknewparameter/", type: "post", cache: false, data: { name: function() { return $("#ValueNewParameter").val(); } } } }, ParameterValue: {required: true} }, messages: { ParameterSelect: { required: 'Este campo es obligatorio', remote: 'La unidad ya tiene establecido este parámetro. Cierre esta ventana y modifíquelo'}, ValueNewParameter: { required: 'Este campo es obligatorio', remote: 'El parámetro ya existe. Haga click en el botón y seleccione su opción'}, ParameterValue: {required: 'Este campo es obligatorio'} }, invalidHandler: function(event, validator) { alert('El formulario no es valido'); }, submitHandler: function(form){ var $form = $(form); var $inputs = $form.find("input, select, button, textarea"); var serializedData = $form.serialize(); var btn = $('#SetParameterUnitAction'); $.ajax({ url: '../request/addparameter/', method: 'POST', cache: false, dataType: 'json', data: serializedData, beforeSend: function(){ $inputs.prop('disabled', true); btn.button('loading'); }, success: function(data){ if(data.success == true){ switch(data.origin){ case 'detail': table_parameters.ajax.url('../request/getparametertable/?x='+data.x).load(null, false); break; default: var nrow = $('#RowOrigin').val(); $('#RequestTechnicalParameter tbody tr:nth-child('+ nrow +')').find('td:nth-child(3)').append(data.html); break; } $('#SetParameterUnit').modal('hide') } else { alert(data.message); } }, complete: function(){ $inputs.prop('disabled', false); btn.button('reset'); grecaptcha.reset(recaptcha3); } }); } });