Skip to content

Instantly share code, notes, and snippets.

@bakura10
Created March 14, 2014 16:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bakura10/9550851 to your computer and use it in GitHub Desktop.
Save bakura10/9550851 to your computer and use it in GitHub Desktop.
'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