Skip to content
This repository has been archived by the owner on Jun 21, 2024. It is now read-only.

Stop removing leading 0 #23

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ Options:
let data = $("#myform").serializeFields({
fieldset_nameattr: "name",
field_selector: "input:enabled,select:enabled,textarea:enabled",
ignored_fields: "input[type='radio']:not(:checked)"
ignored_fields: "input[type='radio']:not(:checked)",
strict_convert_number_type: "true"
})
```

Expand Down
14 changes: 13 additions & 1 deletion dist/jquery-serializeFields.min.js
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
!function(n){"use strict";n.fn.serializeFields=function(e){var t=n.serializeFields;t.extendSettings(e);var i=[];if(!(this.length<1))return 1===this.length?t.parse(n(this)[0]):(this.each(function(){i.push(t.parse(n(this)))}),i)},n.serializeFields={defaultSettings:function(){return{field_selector:"input:enabled,select:enabled,textarea:enabled",fieldset_selector:"fieldset:enabled",fieldset_nameattr:"data-name",ignored_fields:"input[type='radio']:not(:checked)"}},extendSettings:function(e){n.serializeFields.settings=n.serializeFields.defaultSettings(),n.extend(n.serializeFields.settings,e)},getValue:function(e){var t=n(e).val();return"checkbox"==n(e).attr("type")?n(e).is(":checked"):n.isNumeric(t)?parseFloat(t):t},parse:function(e){var i=n.serializeFields,s={};return n(e).children().each(function(){var e,t;n(this).is(i.settings.ignored_fields)||(n(this).is(i.settings.field_selector)?(e=n(this).attr("name")||n(this).attr("id"),t=i.getValue(this),e&&(s[e]=t)):n(this).is(i.settings.fieldset_selector)?(t=n(this).attr(i.settings.fieldset_nameattr))&&(s[t]=i.parse(n(this))):n.extend(s,i.parse(n(this))))}),s}}}(jQuery);
/*!
* jquery-serializeFields v0.0.5
* https://github.com/jonathansp/serializeFields
*
* Copyright (c) 2015

* Jonathan Prates (jonathansp),
* Gabriel Broilo (broilogabriel)
* Cristian Oliveira (CristianOliveiraDaRosa)

* Licensed under GPL license.
*/
!function(e){"use strict";e.fn.serializeFields=function(t){var i=e.serializeFields;i.extendSettings(t);var s=[];if(!(this.length<1))return 1===this.length?i.parse(e(this)[0]):(this.each((function(){s.push(i.parse(e(this)))})),s)},e.serializeFields={defaultSettings:function(){return{field_selector:"input:enabled,select:enabled,textarea:enabled",fieldset_selector:"fieldset:enabled",fieldset_nameattr:"data-name",ignored_fields:"input[type='radio']:not(:checked)",strict_convert_number_type:"false"}},extendSettings:function(t){e.serializeFields.settings=e.serializeFields.defaultSettings(),e.extend(e.serializeFields.settings,t)},getValue:function(t){var i=e.serializeFields,s=e(t).val();return"checkbox"==e(t).attr("type")?e(t).is(":checked"):!0===i.settings.strict_convert_number_type&&e.isNumeric(s)?parseFloat(s):s},parse:function(t){var i=e.serializeFields,s={};return e(t).children().each((function(){if(!e(this).is(i.settings.ignored_fields))if(e(this).is(i.settings.field_selector)){var t=e(this).attr("name")||e(this).attr("id"),n=i.getValue(this);t&&(s[t]=n)}else if(e(this).is(i.settings.fieldset_selector)){var r=e(this).attr(i.settings.fieldset_nameattr);r&&(s[r]=i.parse(e(this)))}else e.extend(s,i.parse(e(this)))})),s}}}(jQuery);
26 changes: 12 additions & 14 deletions src/jquery-serializeFields.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
* https://github.com/jonathansp/serializeFields
*
* Copyright (c) 2015-2022.

* Licensed under GPL license.
*/
(function($) {
(function ($) {

"use strict";

$.fn.serializeFields = function(options) {
$.fn.serializeFields = function (options) {
var sf = $.serializeFields; // namespace
sf.extendSettings(options);

Expand All @@ -24,7 +23,7 @@
return sf.parse($(this)[0]); // return as object
}

this.each(function() {
this.each(function () {
response.push(
sf.parse($(this))
);
Expand All @@ -37,40 +36,40 @@
// and settings
$.serializeFields = {

defaultSettings: function() {
defaultSettings: function () {
return {
field_selector: "input:enabled,select:enabled,textarea:enabled",
fieldset_selector: "fieldset:enabled",
fieldset_nameattr: "data-name",
ignored_fields: "input[type='radio']:not(:checked)"
ignored_fields: "input[type='radio']:not(:checked)",
strict_convert_number_type: "false"
};
},

/**
Function extend default settings

param: options
**/
extendSettings: function(options) {
extendSettings: function (options) {
$.serializeFields.settings = $.serializeFields.defaultSettings();
$.extend($.serializeFields.settings, options);
},

/**
Function to parse value from input by type

param: element
return: value
**/
getValue: function(element) {
getValue: function (element) {
var sf = $.serializeFields;
var value = $(element).val();
var type = $(element).attr("type");

if (type == "checkbox") {
return $(element).is(":checked");
}

if ($.isNumeric(value)) {
if (sf.settings.strict_convert_number_type === true && $.isNumeric(value)) {
return parseFloat(value);
}

Expand All @@ -79,15 +78,14 @@

/**
Function contain all the logic to parse fields to a JSON object

param: element
return: json object
**/
parse: function(element) {
parse: function (element) {
var sf = $.serializeFields;
var data = {};

$(element).children().each(function() {
$(element).children().each(function () {

if (!$(this).is(sf.settings.ignored_fields)) {

Expand Down