Skip to content

Instantly share code, notes, and snippets.

@erichocean
Created September 9, 2008 04:40
Show Gist options
  • Save erichocean/9607 to your computer and use it in GitHub Desktop.
Save erichocean/9607 to your computer and use it in GitHub Desktop.
/**
Call by your subclass anytime you want the view to pick up the current
value from the form and post it out.
@param partialChange (optional) YES if this is a partial change.
@returns result of validation.
*/
fieldValueDidChange: function(partialChange) {
// get the field value and set it.
// if ret is an error, use that instead of the field value.
var ret = this.performValidate(partialChange) ;
if (ret == SC.Validator.NO_CHANGE) return ret ;
// if the validator says everything is OK, then in addition to posting
// out the value, go ahead and pass the value back through itself.
// This way if you have a formatter applied, it will reformat.
//
// Do this BEFORE we set the value so that the valueObserver will not
// overreact.
//
var value = ($ok(ret)) ? this._getFieldValue() : ret ;
if (!partialChange && $ok(ret)) this._setFieldValue(value) ;
if (value != this.get('value')) this.set('value',value) ;
return ret ;
},
// when we lose first responder, blur the text field if needed and show
// the hint text if needed.
/** @private */
willLoseFirstResponder: function() {
if (this._isFocused) {
this._isFocused = false ;
this._updateFieldHint() ;
return this.rootElement.blur() ;
} else {
this._value = this.rootElement.value ;
this.fieldValueDidChange() ;
this._updateFieldHint() ;
return true;
}
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment