Sha256: 700200082361ea4f952d6a3b2cf88275a556a88e46193a3bd50669c78ab15c7a

Contents?: true

Size: 1.58 KB

Versions: 2

Compression:

Stored size: 1.58 KB

Contents

// ==========================================================================
// Project:   SproutCore - JavaScript Application Framework
// Copyright: ©2006-2011 Strobe Inc. and contributors.
//            ©2008-2011 Apple Inc. All rights reserved.
// License:   Licensed under MIT license (see license.js)
// ==========================================================================
/** @class

*/
SC.TextFieldSupport = /** @scope SC.TextFieldSupport.prototype */{
  value: function(key, value) {
    if (value !== undefined) {
      this.$('input').val(value);
    } else {
      value = this.$('input').val();
    }

    return value;
  }.property().idempotent(),

  didCreateLayer: function() {
    SC.Event.add(this.$('input'), 'focus', this, this.focusIn);
    SC.Event.add(this.$('input'), 'blur', this, this.focusOut);
  },

  focusIn: function(event) {
    this.becomeFirstResponder();
    this.tryToPerform('focus', event);
  },

  focusOut: function(event) {
    this.resignFirstResponder();
    this.tryToPerform('blur', event);
  },

  /** @private
    Make sure our input value is synced with any bindings.
    In some cases, such as auto-filling, a value can get
    changed without an event firing. We could do this
    on focusOut, but blur can potentially get called
    after other events.
  */
  willLoseFirstResponder: function() {
    this.notifyPropertyChange('value');
  },

  keyUp: function(event) {
    if (event.keyCode === 13) {
      return this.tryToPerform('insertNewline', event);
    } else if (event.keyCode === 27) {
      return this.tryToPerform('cancel', event);
    }
  }
};

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sproutcore-1.5.0-java lib/frameworks/sproutcore/frameworks/core_foundation/mixins/template_helpers/text_field_support.js
sproutcore-1.5.0.rc.2 lib/frameworks/sproutcore/frameworks/core_foundation/mixins/template_helpers/text_field_support.js