Sha256: 7707cbe0e80e20d9ea9fe368ba157808a80c06e4a9f8300bd55a45e32529c18e

Contents?: true

Size: 1.26 KB

Versions: 2

Compression:

Stored size: 1.26 KB

Contents

if ( Object.isUndefined(RobinsHtmlHelpers) ) { 
	var RobinsHtmlHelpers = { } 
}

RobinsHtmlHelpers.FormFieldHint = Class.create ({
	initialize: function(element, hint, hintClass) {
		this.element = $(element);	
		this.hintText = hint;
		this.hintClass = hintClass;
		this.hintState = false;
		this.showHintWhenBlank();
		this.initEventHandlers();
	},
	initEventHandlers: function() {
		this.onFocusHandler = this.onFocus.bind(this);
		this.element.observe("focus", this.onFocusHandler);
		
		this.onBlurHandler = this.onBlur.bind(this);
		this.element.observe("blur", this.onBlurHandler);
		
		this.onSubmitHandler = this.onSubmit.bind(this);
		this.element.up('form').observe("submit", this.onSubmitHandler);
	},
	showHintWhenBlank: function() {
		if ($F(this.element).empty() ) {
			this.element.value = this.hintText;
		}
		
		this.hintState = ( $F(this.element) == this.hintText );
		
		if (this.hintState) {
			this.element.addClassName(this.hintClass);
		}
		else {
			this.element.removeClassName(this.hintClass);
		}
	},
	onFocus: function() {
		this.element.removeClassName(this.hintClass);
		if( this.hintState )
			this.element.select();
	},
	onBlur: function() {
		this.showHintWhenBlank();
	},
	onSubmit: function() {
		if(this.hintState) 
			this.element.value = null;
	}
});

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
robinsp-robins_html_helpers-0.2.0 rails_generators/robins_html_helpers_resources/templates/robins_html_helpers.js
robinsp-robins_html_helpers-0.2.2 rails_generators/robins_html_helpers_resources/templates/robins_html_helpers.js