Skip to content

Instantly share code, notes, and snippets.

@davidwallacejackson
Created December 26, 2014 21:09
Show Gist options
  • Select an option

  • Save davidwallacejackson/1004b423d0eea7bada83 to your computer and use it in GitHub Desktop.

Select an option

Save davidwallacejackson/1004b423d0eea7bada83 to your computer and use it in GitHub Desktop.
import FormInput from './form-input';
var displayValuePath = 'name';
export default FormInput.extend({
valid: function() {
// Values in 'selection' are always promise proxies for models. By this
// point, they should *always* be resolved, so _data should have a model in
// it (or null).
var selection = this.get('selection');
if (selection && selection._data) {
return true;
}
return false;
}.property('selection'),
selection: function() {
var value = this.get('value');
return this.get('content').findBy(displayValuePath, value);
}.property('value', 'content'),
meaninglessProperty: function() {
return true;
}.property('value')
});
import Ember from 'ember';
export default Ember.TextField.extend({
classNameBindings: ['error'],
/**
* Whether the field is currently in an error state.
*/
error: function() {
if (this.get('required')) {
return !this.get('valid');
}
return true;
}.property('valid'),
required: true,
/**
* Whether the current value of the field is valid. By default, any truthy
* value is valid. Doesn't take 'required' into account.
*/
valid: function() {
if (this.get('value')) {
return true;
}
return false;
}.property('value')
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment