Sha256: 48ffc5661bb746846b87c64580fb554961f1f4c0e196c322b51cbb62d197d1a4

Contents?: true

Size: 1.54 KB

Versions: 15

Compression:

Stored size: 1.54 KB

Contents

Rev.appMixin('StoreInputMixin', {
  componentDidMount: function() {
    if(this.props.defaultValue) {
      this.props.store.set(this.props.field, this.props.defaultValue)
    }
  },

  defaultValue: function() {
    return this.value() || this.props.defaultValue
  },

  value: function() {
    return this.props.store.get(this.props.field)
  },

  headPathPart: function() {
    return this.props.field.split('.')[0]
  },

  tailPathParts: function() {
    var parts = this.props.field.split('.')
    parts.shift()
    return parts
  },

  railsPath: function() {
    return (this.props.baseName || this.headPathPart()) + '[' + this.tailPathParts().join('][')  +']'
  },

  name: function() {
    return this.props.name || this.railsPath()
  },

  isCheckbox: function() {
    return this.props.type == 'checkbox'
  },

  onFieldChange: function(e) {
    this.props.store.resetErrorFor(this.props.field)
    if(this.isCheckbox()) {
      this.props.store.set(this.props.field, e.target.checked)
    } else {
      this.props.store.set(this.props.field, e.target.value)
    }
  },

  onBlur: function(e) {
    var validator = this.props.store["validate#{ _.str.classify(this.props.field) }"]
    if(typeof validator !== 'undefined') {
      error = validator.bind(this.props.model)()
      if(error) {
        response = { responseJSON: { errors: {} } }
        response.responseJSON.errors[this.props.field] = [ error ]
        this.props.model.trigger('error', this.props.model, response, {})
      }
    }

    if(this.props.onBlur) {
      this.props.onBlur(e)
    }
  }
})

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
revelry_data-0.1.6 app/assets/javascripts/revelry_data/mixins/StoreInputMixin.es6
revelry_data-0.0.15 app/assets/javascripts/revelry_data/mixins/StoreInputMixin.es6
revelry_data-0.1.5 app/assets/javascripts/revelry_data/mixins/StoreInputMixin.es6
revelry_data-0.1.4 app/assets/javascripts/revelry_data/mixins/StoreInputMixin.es6
revelry_data-0.0.14 app/assets/javascripts/revelry_data/mixins/StoreInputMixin.es6
revelry_data-0.0.8.1 app/assets/javascripts/revelry_data/mixins/StoreInputMixin.es6
revelry_data-0.0.13 app/assets/javascripts/revelry_data/mixins/StoreInputMixin.es6
revelry_data-0.1.3 app/assets/javascripts/revelry_data/mixins/StoreInputMixin.es6
revelry_data-0.0.12 app/assets/javascripts/revelry_data/mixins/StoreInputMixin.es6
revelry_data-0.1.2 app/assets/javascripts/revelry_data/mixins/StoreInputMixin.es6
revelry_data-0.1.1 app/assets/javascripts/revelry_data/mixins/StoreInputMixin.es6
revelry_data-0.0.10 app/assets/javascripts/revelry_data/mixins/StoreInputMixin.es6
revelry_data-0.1.0 app/assets/javascripts/revelry_data/mixins/StoreInputMixin.es6
revelry_data-0.0.8 app/assets/javascripts/revelry_data/mixins/StoreInputMixin.es6
revelry_data-0.0.7 app/assets/javascripts/revelry_data/mixins/StoreInputMixin.es6