From d5ad7dfa16e179c0e67a59af84538daee0c24a41 Mon Sep 17 00:00:00 2001 From: Marcos Mariano Date: Fri, 16 Jan 2015 02:52:13 -0200 Subject: [PATCH] Radio fix + Form serialize function This fixes semantic .ui.radio.checkbox resetting as well adds a serialize function to the form. --- src/definitions/behaviors/form.js | 32 +++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/src/definitions/behaviors/form.js b/src/definitions/behaviors/form.js index 6228040eb..7dc03ba02 100644 --- a/src/definitions/behaviors/form.js +++ b/src/definitions/behaviors/form.js @@ -141,7 +141,8 @@ $.fn.form = function(fields, parameters) { ; switch (type) { - case 'checkbox': + case 'checkbox': + case 'radio': $field.data('defaultValue', $field.is(':checked')); break; default: @@ -167,7 +168,8 @@ $.fn.form = function(fields, parameters) { case 'select-multiple': $parent.is('.ui.dropdown') && $parent.dropdown('restore defaults'); break; - case 'checkbox': + case 'checkbox': + case 'radio': $parent.is('.ui.checkbox') && $parent.checkbox(defaultValue ? 'check' : 'uncheck'); break; default: @@ -179,6 +181,32 @@ $.fn.form = function(fields, parameters) { ; }, + serialize: function () { + var data = {}; + + $field + .each(function () { + var + $field = $(this), + type = $field.prop('type'), + name = $field.prop('name') + ; + + switch (type) { + case 'checkbox': + case 'radio': + if ($field.is(':checked')) + data[name] = $field.val(); + break; + default: + data[name] = $field.val(); + } + }) + ; + + return data; + }, + removeEvents: function() { $module .off(eventNamespace)