Input disable not found in serialize

Asked

Viewed 43 times

0

If the form I have is validated, I disable the form, this way:

 $("#Editar :input").prop("disabled", true);

But I have a function that serialize, and if I’m with the forms disabled, they do not find the value. There is some way to disable the fields, but they are still found ?

This is the function I use, it compares the form when it is loaded, and the form at the time of the action, and how it is disabled, it does not find values.

   $(function () {
        var init_form = $('#Editar').serialize(); 
    $(':submit').click(function () { window.onbeforeunload = null; }); window.onbeforeunload = function () { var check_form = $('#Editar').serialize(); console.log(check_form); console.log(init_form); if (check_form === init_form) return null; return 'Os dados do formulário não foram salvos, deseja permanecer nesta página?'; };
 });

On the console, what appears blank is the var check_form = $('#Editar').serialize(); the other not, how to correct?

1 answer

1


The disable property really isn’t read in serialize, try changing the field property to readonly.

$('#inputId').prop('readonly', true);

That should solve your problem.

  • It worked fine, thank you.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.