diff --git a/README.md b/README.md index 84b9d66..cd61c9b 100644 --- a/README.md +++ b/README.md @@ -277,6 +277,7 @@ Available options: * **defaultTypes: {defaults}**, contains the orignal type functions `string`, `number`, `boolean`, `null`, `array`, `object` and `skip`. * **defaultType: "string"**, fields that have no `:type` suffix and no `data-value-type` attribute are parsed with the `string` type function by default, but it could be changed to use a different type function instead. * **disableColonTypes: true**, do not parse input names as types, allowing field names to use colons. If this option is used, types can still be specified with the `data-value-type` attribute. For example `` will be parsed as a number. + * **includeDisabled: false**, if true, disabled :input's included. More details about these options in the sections below. diff --git a/jquery.serializejson.js b/jquery.serializejson.js index ed699eb..43c6139 100644 --- a/jquery.serializejson.js +++ b/jquery.serializejson.js @@ -1,7 +1,8 @@ +/* --- */ /*! SerializeJSON jQuery plugin. https://github.com/marioizquierdo/jquery.serializeJSON - version 3.2.1 (Feb, 2021) + version 3.2.2 (Mar, 2021) Copyright (c) 2012-2021 Mario Izquierdo Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) @@ -50,6 +51,10 @@ if (type === "skip") { return; // ignore fields with type skip } + if(obj.multiple) { + type = 'array'; + } + if (!type) { type = opts.defaultType; // "string" by default } @@ -108,7 +113,8 @@ "disableColonTypes", "customTypes", "defaultTypes", - "defaultType" + "defaultType", + "includeDisabled" ]; for (var opt in options) { if (validOpts.indexOf(opt) === -1) { @@ -133,10 +139,9 @@ }).filter(function() { var $el = $(this); var type = this.type; - // Filter with the standard W3C rules for successful controls: http://www.w3.org/TR/html401/interact/forms.html#h-17.13.2 return this.name && // must contain a name attribute - !$el.is(":disabled") && // must not be disable (use .is(":disabled") so that fieldset[disabled] works) + (!$el.is(":disabled") || $el.is(":disabled") && opts.includeDisabled) && // must not be disable (use .is(":disabled") so that fieldset[disabled] works) rsubmittable.test(this.nodeName) && !rsubmitterTypes.test(type) && // only serialize submittable fields (and not buttons) (this.checked || !rcheckableType.test(type) || f.getCheckboxUncheckedValue($el, opts) != null); // skip unchecked checkboxes (unless using opts) @@ -154,13 +159,14 @@ } if (isArray(val)) { - return $.map(val, function(val) { - return { name: el.name, value: val.replace(rCRLF, "\r\n"), el: el }; - } ); + if(!val.length) { + return { name: el.name, el: el } + } + return $.map(val, function(val) { + return { name: el.name, value: val.replace(rCRLF, "\r\n"), el: el}; + } ); } - return { name: el.name, value: val.replace(rCRLF, "\r\n"), el: el }; - }).get(); }, @@ -336,3 +342,5 @@ var isValidArrayIndex = function(val) { return /^[0-9]+$/.test(String(val)); }; // 1,2,3,4 ... are valid array indexes var isArray = Array.isArray || function(obj) { return Object.prototype.toString.call(obj) === "[object Array]"; }; })); + +