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) {
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)

Loading…
Cancel
Save