|
|
@ -58,23 +58,7 @@ $.fn.form = function(fields, parameters) { |
|
|
|
|
|
|
|
initialize: function() { |
|
|
|
module.verbose('Initializing form validation', $module, validation, settings); |
|
|
|
if(settings.keyboardShortcuts) { |
|
|
|
$field |
|
|
|
.on('keydown' + eventNamespace, module.event.field.keydown) |
|
|
|
; |
|
|
|
} |
|
|
|
$module |
|
|
|
.on('submit' + eventNamespace, module.validate.form) |
|
|
|
; |
|
|
|
$field |
|
|
|
.on('blur' + eventNamespace, module.event.field.blur) |
|
|
|
; |
|
|
|
$submit |
|
|
|
.on('click' + eventNamespace, module.submit) |
|
|
|
; |
|
|
|
$field |
|
|
|
.on(module.get.changeEvent() + eventNamespace, module.event.field.change) |
|
|
|
; |
|
|
|
module.bindEvents(); |
|
|
|
module.instantiate(); |
|
|
|
}, |
|
|
|
|
|
|
@ -88,8 +72,8 @@ $.fn.form = function(fields, parameters) { |
|
|
|
|
|
|
|
destroy: function() { |
|
|
|
module.verbose('Destroying previous module', instance); |
|
|
|
module.removeEvents(); |
|
|
|
$module |
|
|
|
.off(eventNamespace) |
|
|
|
.removeData(moduleNamespace) |
|
|
|
; |
|
|
|
}, |
|
|
@ -106,6 +90,51 @@ $.fn.form = function(fields, parameters) { |
|
|
|
; |
|
|
|
}, |
|
|
|
|
|
|
|
bindEvents: function() { |
|
|
|
if(settings.keyboardShortcuts) { |
|
|
|
$field |
|
|
|
.on('keydown' + eventNamespace, module.event.field.keydown) |
|
|
|
; |
|
|
|
} |
|
|
|
$module |
|
|
|
.on('submit' + eventNamespace, module.validate.form) |
|
|
|
; |
|
|
|
$field |
|
|
|
.on('blur' + eventNamespace, module.event.field.blur) |
|
|
|
; |
|
|
|
$submit |
|
|
|
.on('click' + eventNamespace, module.submit) |
|
|
|
; |
|
|
|
$field |
|
|
|
.each(function() { |
|
|
|
var |
|
|
|
type = $(this).prop('type'), |
|
|
|
inputEvent = module.get.changeEvent(type) |
|
|
|
; |
|
|
|
if(settings.inline == true) { |
|
|
|
} |
|
|
|
$(this) |
|
|
|
.on(inputEvent + eventNamespace, module.event.field.change) |
|
|
|
; |
|
|
|
}) |
|
|
|
; |
|
|
|
}, |
|
|
|
|
|
|
|
removeEvents: function() { |
|
|
|
$module |
|
|
|
.off(eventNamespace) |
|
|
|
; |
|
|
|
$field |
|
|
|
.off(eventNamespace) |
|
|
|
; |
|
|
|
$submit |
|
|
|
.off(eventNamespace) |
|
|
|
; |
|
|
|
$field |
|
|
|
.off(eventNamespace) |
|
|
|
; |
|
|
|
}, |
|
|
|
|
|
|
|
event: { |
|
|
|
field: { |
|
|
|
keydown: function(event) { |
|
|
@ -171,13 +200,18 @@ $.fn.form = function(fields, parameters) { |
|
|
|
}, |
|
|
|
|
|
|
|
get: { |
|
|
|
changeEvent: function() { |
|
|
|
return (document.createElement('input').oninput !== undefined) |
|
|
|
? 'input' |
|
|
|
: (document.createElement('input').onpropertychange !== undefined) |
|
|
|
? 'propertychange' |
|
|
|
: 'keyup' |
|
|
|
; |
|
|
|
changeEvent: function(type) { |
|
|
|
if(type == 'checkbox' || type == 'radio') { |
|
|
|
return 'change'; |
|
|
|
} |
|
|
|
else { |
|
|
|
return (document.createElement('input').oninput !== undefined) |
|
|
|
? 'input' |
|
|
|
: (document.createElement('input').onpropertychange !== undefined) |
|
|
|
? 'propertychange' |
|
|
|
: 'keyup' |
|
|
|
; |
|
|
|
} |
|
|
|
}, |
|
|
|
field: function(identifier) { |
|
|
|
module.verbose('Finding field with identifier', identifier); |
|
|
|