'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