Browse Source

Radio fix + Form serialize function

This fixes semantic .ui.radio.checkbox resetting as well adds a
serialize function to the form.
pull/1630/head
Marcos Mariano 9 years ago
parent
commit
d5ad7dfa16
1 changed files with 30 additions and 2 deletions
  1. 32
      src/definitions/behaviors/form.js

32
src/definitions/behaviors/form.js

@ -141,7 +141,8 @@ $.fn.form = function(fields, parameters) {
; ;
switch (type) { switch (type) {
case 'checkbox':
case 'checkbox':
case 'radio':
$field.data('defaultValue', $field.is(':checked')); $field.data('defaultValue', $field.is(':checked'));
break; break;
default: default:
@ -167,7 +168,8 @@ $.fn.form = function(fields, parameters) {
case 'select-multiple': case 'select-multiple':
$parent.is('.ui.dropdown') && $parent.dropdown('restore defaults'); $parent.is('.ui.dropdown') && $parent.dropdown('restore defaults');
break; break;
case 'checkbox':
case 'checkbox':
case 'radio':
$parent.is('.ui.checkbox') && $parent.checkbox(defaultValue ? 'check' : 'uncheck'); $parent.is('.ui.checkbox') && $parent.checkbox(defaultValue ? 'check' : 'uncheck');
break; break;
default: 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() { removeEvents: function() {
$module $module
.off(eventNamespace) .off(eventNamespace)

Loading…
Cancel
Save