app/assets/javascripts/semantic-ui/modules/behavior/form.js in semantic-ui-rails-0.12.5 vs app/assets/javascripts/semantic-ui/modules/behavior/form.js in semantic-ui-rails-0.13.0
- old
+ new
@@ -56,27 +56,11 @@
module = {
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();
},
instantiate: function() {
module.verbose('Storing instance of module', module);
@@ -86,12 +70,12 @@
;
},
destroy: function() {
module.verbose('Destroying previous module', instance);
+ module.removeEvents();
$module
- .off(eventNamespace)
.removeData(moduleNamespace)
;
},
refresh: function() {
@@ -104,10 +88,55 @@
$module
.submit()
;
},
+ 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) {
var
$field = $(this),
@@ -169,16 +198,21 @@
}
},
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);
if( $field.filter('#' + identifier).size() > 0 ) {
return $field.filter('#' + identifier);