Skip to content

Commit

Permalink
Add aria role to error
Browse files Browse the repository at this point in the history
  • Loading branch information
bakura10 committed Dec 9, 2014
1 parent 7082a1a commit 6215908
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
17 changes: 10 additions & 7 deletions addon/mixins/validatable-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,21 @@ export default Ember.Mixin.create({
* @returns {void}
*/
validate: function() {
var input = this.get('element');
var input = this.get('element'),
jQueryElement = Ember.$(input);

// According to spec, inputs that have "formnovalidate" should bypass any validation
if (input.hasAttribute('formnovalidate')) {
return;
}

// Validate Textarea with proper text and not accept only blank spaces, only new line characters.
if(input.tagName.toLowerCase() === 'textarea') {
var content = Ember.$.trim(Ember.$(input).val());
// Textareas do not support "pattern" attribute. As a consequence, if you set a "required" attribute
// and only add blank spaces or new lines, then it is considered as valid (although it makes little sense).
if(input.tagName.toLowerCase() === 'textarea' && input.hasAttribute('required')) {
var content = Ember.$.trim(jQueryElement.val());

if(content.length === 0) {
Ember.$(input).val('');
jQueryElement.val('');
}
}

Expand All @@ -128,7 +131,7 @@ export default Ember.Mixin.create({
// run also on keyup. This makes the UX better as it removes error message as you type when
// you try to fix the errors
if (!this.get('wasValidated')) {
Ember.$(input).on('keyup', Ember.run.bind(this, this.validate));
jQueryElement.on('keyup', Ember.run.bind(this, this.validate));
this.set('wasValidated', true);
}
},
Expand Down Expand Up @@ -161,7 +164,7 @@ export default Ember.Mixin.create({
} else {
parent.addClass('has-error');
element.next('.input-error').remove();
element.after('<p class="input-error">' + errorMessage + '</p>');
element.after('<p class="input-error" role="alert">' + errorMessage + '</p>');
}
}.observes('errorMessage'),

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ember-cli-html5-validation",
"version": "0.0.7",
"version": "0.0.8",
"directories": {
"doc": "doc",
"test": "tests"
Expand All @@ -20,7 +20,7 @@
"body-parser": "^1.2.0",
"broccoli-asset-rev": "0.3.1",
"broccoli-ember-hbs-template-compiler": "^1.6.1",
"ember-cli": "0.1.2",
"ember-cli": "0.1.4",
"ember-cli-content-security-policy": "0.3.0",
"ember-export-application-global": "^1.0.0",
"ember-cli-ic-ajax": "0.1.1",
Expand Down

0 comments on commit 6215908

Please sign in to comment.