jquery remove in a form all disabled / readonly properties of the inputs and select boxes

1

I'm trying to use jquery to capture a form and remove in the form all the disabled / readonly properties that contain the inputs and select boxes, without affecting the user's view, I've tried with two versions, but I did not none works and affect the user's (html) view, also try changing the .each () to .find ():

var $form       = $("#formarea");
var $form       = $form.each('input').prop('readonly', false);
var $form       = $form.each('select').prop('disabled', false);

And save it in an object to be sent with ajax including the input and select box that are disabled or readonly:

  var   formData    = new FormData();
  var   params      = $form.serializeArray();

    $.ajax({
                    url: $form.attr('action'),
                    data: formData,
                    cache: false,
                    contentType: false,
                    processData: false,
                    type: 'POST',
                    error: function(xhr,status,error){console.log('Error')},
                    success:    function(response) {console.log('Logrado')}
    });

I'm getting the following error:

jquery.min.js:2 Uncaught TypeError: b.call is not a function
    at Function.each (jquery.min.js:2)
    at jQuery.fn.init.each (jquery.min.js:2)
    at HTMLButtonElement.<anonymous> (ajax.event.js:263)
    at HTMLFormElement.dispatch (jquery.min.js:3)
    at HTMLFormElement.q.handle (jquery.min.js:3)
each @ jquery.min.js:2
each @ jquery.min.js:2
(anonymous) @ ajax.event.js:263
dispatch @ jquery.min.js:3
q.handle @ jquery.min.js:3

this line:

at HTMLButtonElement.<anonymous> (ajax.event.js:263) 

refer to this:

var $form       = $form.each('select').prop('disabled', false);

How do I fix it?

    
asked by Francisco Núñez 18.08.2017 в 19:51
source

1 answer

0

I solved it by adding this code:

        var inputs = $("input[readonly]");
        $.each(inputs, function (obj, v) {
            var name = $(v).attr("name");
            var val = $(v).val();
            formData.append(name, val);
        });
        var selects = $("select[disabled]");
        $.each(selects, function (obj, v) {
            var name = $(v).attr("name");
            var val = $(v).val()
            formData.append(name, val);
        });
    
answered by 19.08.2017 / 16:35
source