Created
September 25, 2015 17:22
-
-
Save ryanschuhler/821fdde79571b743e619 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| AUI.add( | |
| 'osb-form', | |
| function(A) { | |
| var OSBForm = A.Component.create( | |
| { | |
| ATTRS: { | |
| customRules: { | |
| value: A.Lang.emptyFn | |
| }, | |
| fieldClassName: { | |
| value: 'field-wrapper' | |
| }, | |
| fieldStrings: { | |
| value: {} | |
| }, | |
| formId: { | |
| value: '#osbForm' | |
| }, | |
| rules: { | |
| value: {} | |
| } | |
| }, | |
| NAME: 'osb-form', | |
| prototype: { | |
| bindUI: function() { | |
| var instance = this; | |
| A.on('load', instance.syncUI, instance); | |
| }, | |
| syncUI: function() { | |
| var instance = this; | |
| instance._initializeValidator(); | |
| var form = A.one(instance.get('formId')); | |
| instance._delegateFieldFocused(form); | |
| instance._delegateFieldCheck(form); | |
| }, | |
| _addCustomRules: function(config) { | |
| var instance = this; | |
| config.RULES.custom = instance.get('customRules'); | |
| config.STRINGS.custom = A.config.FormValidator.STRINGS.required; | |
| }; | |
| _delegateFieldCheck: function(form) { | |
| var instance = this; | |
| form.delegate( | |
| 'change', | |
| function(event) { | |
| var node = event.currentTarget; | |
| instance._fieldCheck(node); | |
| }, | |
| '.' + instance.get('fieldClassName') | |
| ); | |
| }, | |
| _delegateFieldFocused: function(form) { | |
| var instance = this; | |
| form.delegate( | |
| 'focus', | |
| function() { | |
| this.addClass('field-focused'); | |
| }, | |
| '.' + instance.get('fieldClassName') | |
| ); | |
| form.delegate( | |
| 'blur', | |
| function() { | |
| this.removeClass('field-focused'); | |
| }, | |
| '.' + instance.get('fieldClassName') | |
| ); | |
| }, | |
| _fieldCheck: function(node) { | |
| var input = node.one('.field'); | |
| if (!input) { | |
| input = node.one('select'); | |
| } | |
| if (!input) { | |
| input = node.one('input'); | |
| } | |
| if (input.get('value') != "") { | |
| node.addClass('field-filled'); | |
| } | |
| else { | |
| node.removeClass('field-filled'); | |
| } | |
| }, | |
| _initializeValidator: function() { | |
| var instance = this; | |
| var config = new A.FormValidator( | |
| { | |
| boundingBox: instance.get('formId'), | |
| fieldContainer: '.' + instance.get('fieldClassName'), | |
| fieldStrings: instance.get('fieldStrings'), | |
| rules: instance.get('rules'), | |
| validateOnInput: true | |
| } | |
| ); | |
| instance._addCustomRules(config); | |
| } | |
| } | |
| } | |
| ); | |
| A.OSBForm = OSBForm; | |
| }, | |
| '2.0', | |
| { | |
| requires: ['aui-base', 'aui-form-validator', 'event'] | |
| } | |
| ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment