Created
March 14, 2014 16:10
-
-
Save bakura10/9550851 to your computer and use it in GitHub Desktop.
This file contains 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
'use strict'; | |
/** | |
* Basic form | |
*/ | |
module.exports = App.ValidatableFormComponent = Ember.Component.extend({ | |
/** | |
* @type {String} | |
*/ | |
tagName: 'form', | |
/** | |
* @type {Array} | |
*/ | |
attributeBindings: ['novalidate'], | |
/** | |
* Prevent the built-in browser navigation error messages to pop up | |
* | |
* @type {boolean} | |
*/ | |
novalidate: true, | |
/** | |
* Send the action bound to the submit event | |
* | |
* @returns {boolean} | |
*/ | |
submit: function() { | |
this.sendAction(); | |
return false; | |
} | |
}); | |
Ember.TextField.reopen({ | |
/** | |
* Get the error message on focus out and show them | |
* | |
* @param event | |
*/ | |
focusOut: function(event) { | |
var target = event.target; | |
if (!target.checkValidity()) { | |
var validationMessage = target.validationMessage, | |
element = $(target); | |
Ember.run.schedule('render', function() { | |
element.siblings('.input-error').remove(); | |
element.after('<p class="input-error">' + validationMessage + '</p>'); | |
}); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment