|
@ -46,6 +46,7 @@ $.fn.form = function(fields, parameters) { |
|
|
$message = $(this).find(selector.message), |
|
|
$message = $(this).find(selector.message), |
|
|
$prompt = $(this).find(selector.prompt), |
|
|
$prompt = $(this).find(selector.prompt), |
|
|
$submit = $(this).find(selector.submit), |
|
|
$submit = $(this).find(selector.submit), |
|
|
|
|
|
$reset = $(this).find(selector.reset), |
|
|
|
|
|
|
|
|
formErrors = [], |
|
|
formErrors = [], |
|
|
|
|
|
|
|
@ -59,6 +60,7 @@ $.fn.form = function(fields, parameters) { |
|
|
initialize: function() { |
|
|
initialize: function() { |
|
|
module.verbose('Initializing form validation', $module, validation, settings); |
|
|
module.verbose('Initializing form validation', $module, validation, settings); |
|
|
module.bindEvents(); |
|
|
module.bindEvents(); |
|
|
|
|
|
module.setDefaults(); |
|
|
module.instantiate(); |
|
|
module.instantiate(); |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
@ -115,6 +117,7 @@ $.fn.form = function(fields, parameters) { |
|
|
; |
|
|
; |
|
|
// attach submit events
|
|
|
// attach submit events
|
|
|
module.attachEvents($submit, 'submit'); |
|
|
module.attachEvents($submit, 'submit'); |
|
|
|
|
|
module.attachEvents($reset, 'reset'); |
|
|
|
|
|
|
|
|
$field |
|
|
$field |
|
|
.each(function() { |
|
|
.each(function() { |
|
@ -129,6 +132,51 @@ $.fn.form = function(fields, parameters) { |
|
|
; |
|
|
; |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
setDefaults: function() { |
|
|
|
|
|
$field |
|
|
|
|
|
.each(function () { |
|
|
|
|
|
var |
|
|
|
|
|
$field = $(this), |
|
|
|
|
|
type = $field.prop('type') |
|
|
|
|
|
; |
|
|
|
|
|
|
|
|
|
|
|
switch (type) { |
|
|
|
|
|
case 'checkbox': |
|
|
|
|
|
$field.data('defaultValue', $field.is(':checked')); |
|
|
|
|
|
break; |
|
|
|
|
|
default: |
|
|
|
|
|
$field.data('defaultValue', $field.val()); |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
|
|
|
; |
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
reset: function() { |
|
|
|
|
|
$field |
|
|
|
|
|
.each(function () { |
|
|
|
|
|
var |
|
|
|
|
|
$field = $(this), |
|
|
|
|
|
$parent = $field.parent(), |
|
|
|
|
|
type = $field.prop('type'), |
|
|
|
|
|
defaultValue = $field.data('defaultValue') |
|
|
|
|
|
; |
|
|
|
|
|
|
|
|
|
|
|
switch (type) { |
|
|
|
|
|
case 'hidden': |
|
|
|
|
|
$parent.is('.ui.dropdown') && $parent.dropdown('restore defaults'); |
|
|
|
|
|
break; |
|
|
|
|
|
case 'checkbox': |
|
|
|
|
|
$parent.is('.ui.checkbox') && $parent.checkbox(defaultValue ? 'check' : 'uncheck'); |
|
|
|
|
|
break; |
|
|
|
|
|
default: |
|
|
|
|
|
$field.val(defaultValue); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$field.parents('.field').removeClass(settings.className.error); |
|
|
|
|
|
}) |
|
|
|
|
|
; |
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
removeEvents: function() { |
|
|
removeEvents: function() { |
|
|
$module |
|
|
$module |
|
|
.off(eventNamespace) |
|
|
.off(eventNamespace) |
|
@ -670,7 +718,8 @@ $.fn.form.settings = { |
|
|
checkbox: 'input[type="checkbox"], input[type="radio"]', |
|
|
checkbox: 'input[type="checkbox"], input[type="radio"]', |
|
|
input : 'input', |
|
|
input : 'input', |
|
|
prompt : '.prompt.label', |
|
|
prompt : '.prompt.label', |
|
|
submit : '.submit' |
|
|
|
|
|
|
|
|
submit : '.submit', |
|
|
|
|
|
reset : '.reset' |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
className : { |
|
|
className : { |
|
|