(Question updated to reflect real issue)
I just realized that serializeArray
is not fetching content from disabled fields.
A set of
you can use readonly
serializeArray() can read it.
$('#field').removeAttr('disabled');
var formData = $(this).serializeArray();
$('#field').attr('disabled', 'disabled');
The solution above is better - alternatively you can just remove the disabled attribute from the element, serialize the fields then re-add the attribute.
This is expected behavior and won't be fixed. Here is a workaround
function serializeJSONIncludingDisabledFields (form) {
var fields = form.find('[disabled]');
fields.prop('disabled', false);
var json = form.serializeJSON();
fields.prop('disabled', true);
return json;
}
Link to the issue
Try this
var data = $('form').serializeAllArray();
And here is the small plugin that is used
(function ($) {
$.fn.serializeAllArray = function () {
var obj = {};
$('input',this).each(function () {
obj[this.name] = $(this).val();
});
return $.param(obj);
}
})(jQuery);
You can also try enabling all your element's just to serialize them and then disable them after serializing.
var myform = $('#form');
var disabled = myform.find(':input:disabled').removeAttr('disabled');
var serialized = myform.serializeArray();
disabled.attr('disabled','disabled');