Created
July 29, 2014 12:40
-
-
Save validkeys/27093f0c436423b5f219 to your computer and use it in GitHub Desktop.
Validated Ember Input
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
{{v-input classNames="spec-fn" value=first_name name="first_name" model=model}} |
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
import Ember from 'ember'; | |
export default Ember.Component.extend({ | |
init: function(){ | |
this._super(); | |
this.set('errors',[]); | |
}, | |
model: {}, | |
name: "", | |
errors: [], | |
updateErrors: function() { | |
if (this.get('model.isValid')){ | |
return this.set('errors',[]); | |
} else { | |
var msgs = this.get('model.errors.' + this.get('name')); | |
return this.set('errors', msgs); | |
} | |
}, | |
didInsertElement: function(){ | |
this.addObserver("model.errors." + this.get('name'), this.updateErrors); | |
} | |
}); |
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
{{input type="text" name=name value=value classNames=classNames}} | |
{{#if errors}} | |
<ul> | |
{{#each error in errors}} | |
<li>{{error}}</li> | |
{{/each}} | |
</ul> | |
{{/if}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment