Sha256: 65df42dce37679da7955217135f4a89c5dddb4e865b01c7df7a8dedcafdda63b

Contents?: true

Size: 1.62 KB

Versions: 9

Compression:

Stored size: 1.62 KB

Contents

pageflow.TextInputView = Backbone.Marionette.ItemView.extend({
  mixins: [pageflow.inputView],

  template: 'pageflow/ui/templates/inputs/text_input',

  ui: {
    input: 'input'
  },

  events: {
    'change': 'onChange'
  },

  onRender: function() {
    this.updatePlaceholder();
    this.load();
    this.validate();

    this.listenTo(this.model, 'change:' + this.options.propertyName, this.load);
  },

  onChange: function() {
    this.validate();
    this.save();
  },

  onClose: function() {
    this.save();
  },

  save: function() {
    this.model.set(this.options.propertyName, this.ui.input.val());
  },

  load: function() {
    this.ui.input.val(this.model.get(this.options.propertyName));
  },

  validate: function() {
    if (this.options.required && !this.ui.input.val()) {
      this.displayValidationError(I18n.t('pageflow.ui.views.inputs.text_input_view.required_field'));
    }
    else {
      this.resetValidationError();
    }
  },

  displayValidationError: function(message) {
    this.$el.addClass('invalid');
    this.ui.input.attr('title', message);
  },

  resetValidationError: function(message) {
    this.$el.removeClass('invalid');
    this.ui.input.attr('title', '');
  },

  updatePlaceholder: function() {
    this.ui.input.attr('placeholder', this.placeholderText());
  },

  placeholderText: function() {
    if (!this.options.disabled || !this.options.hidePlaceholderIfDisabled) {
      return this.options.placeholder || this.placholderModelValue();
    }
  },

  placholderModelValue: function() {
    return this.options.placeholderModel && this.options.placeholderModel.get(this.options.propertyName);
  }
});

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
pageflow-0.11.4 app/assets/javascripts/pageflow/ui/views/inputs/text_input_view.js
pageflow-0.11.3 app/assets/javascripts/pageflow/ui/views/inputs/text_input_view.js
pageflow-0.11.2 app/assets/javascripts/pageflow/ui/views/inputs/text_input_view.js
pageflow-0.11.1 app/assets/javascripts/pageflow/ui/views/inputs/text_input_view.js
pageflow-0.11.0 app/assets/javascripts/pageflow/ui/views/inputs/text_input_view.js
pageflow-0.10.0 app/assets/javascripts/pageflow/ui/views/inputs/text_input_view.js
pageflow-0.9.2 app/assets/javascripts/pageflow/ui/views/inputs/text_input_view.js
pageflow-0.9.1 app/assets/javascripts/pageflow/ui/views/inputs/text_input_view.js
pageflow-0.9.0 app/assets/javascripts/pageflow/ui/views/inputs/text_input_view.js