inputEx Documentation
Back to homepage
inputEx Documentation
> StringField.js
1.0.0
This is the source view for StringField.js
/** * @class Basic string field (equivalent to the input type "text") * @extends inputEx.Field * @constructor * @param {Object} options inputEx.Field options object * options:
*
regexp: regular expression used to validate (otherwise it always validate)
*
size: size attribute of the input
*
numbersOnly: boolean, accept only numbers if true
*
*/ inputEx.StringField = function(options) { inputEx.StringField.superclass.constructor.call(this, options); }; YAHOO.extend(inputEx.StringField, inputEx.Field); /** * Add the option "size" */ inputEx.StringField.prototype.setOptions = function() { inputEx.StringField.superclass.setOptions.call(this); // Field Size this.options.size = this.options.size || 20; }; inputEx.StringField.prototype.renderComponent = function() { // Attributes of the input field var attributes = {}; attributes.type = 'text'; attributes.size = this.options.size; if(this.options.name) attributes.name = this.options.name; // Create the node this.el = inputEx.cn('input', attributes); // Append it to the main element this.divEl.appendChild(this.el); }; inputEx.StringField.prototype.getEl = function() { return this.divEl; }; inputEx.StringField.prototype.initEvents = function() { // The "input" event doesn't exist in IE so we use the "keypress" with a setTimeout to wait until the new value has been set //YAHOO.util.Event.addListener(this.el, "input", this.onInput, this, true); var that = this; YAHOO.util.Event.addListener(this.el, "keypress", function(e) { setTimeout(function() { that.onInput(e); },50); }); YAHOO.util.Event.addListener(this.el, "change", this.onChange, this, true); YAHOO.util.Event.addListener(this.el, "focus", this.onFocus, this, true); YAHOO.util.Event.addListener(this.el, "blur", this.onBlur, this, true); }; inputEx.StringField.prototype.getValue = function() { return this.el.value; }; /** * Function to set the value * @param {String} value The new value */ inputEx.StringField.prototype.setValue = function(value) { this.el.value = value; }; /** * onInput is called 50ms after a "keypress" event */ inputEx.StringField.prototype.onInput = function(e) { if(this.options.numbersOnly) { this.setValue( this.getValue().replace(/[^0-9]/g,'') ); } this.setClassFromState(); }; /** * Uses the optional regexp to validate the field value */ inputEx.StringField.prototype.validate = function() { // if we are using a regular expression if( this.options.regexp ) { return this.getValue().match(this.options.regexp); } return true; }; /** * Disable the field */ inputEx.StringField.prototype.disable = function() { this.el.disabled = true; }; /** * Enable the field */ inputEx.StringField.prototype.enable = function() { this.el.disabled = false; }; /** * Register this class as "string" type */ inputEx.registerType("string", inputEx.StringField);
Pages
Index
Getting Started
Overview
Field development
DOM functions
Internationalization
Examples
Classes
(treeview)
Array
inputEx
inputEx.AutoComplete
inputEx.CheckBox
inputEx.ColorField
inputEx.DateField
inputEx.EmailField
inputEx.Field
inputEx.Form
inputEx.FrenchDate
inputEx.FrenchPhone
inputEx.Group
inputEx.HiddenField
inputEx.InPlaceEdit
inputEx.IPv4Field
inputEx.ListField
inputEx.PairField
inputEx.PasswordField
inputEx.RTEField
inputEx.SelectField
inputEx.StringField
inputEx.Textarea
inputEx.TreeField
inputEx.TypeField
inputEx.UneditableField
inputEx.UpperCaseField
inputEx.UrlField
Files
AutoComplete.js
CheckBox.js
ColorField.js
DateField.js
EmailField.js
Field.js
Form.js
fr_messages.js
FrenchDate.js
FrenchPhone.js
Group.js
HiddenField.js
InPlaceEdit.js
inputex.js
IPv4Field.js
ListField.js
PairField.js
PasswordField.js
RTEField.js
SelectField.js
StringField.js
Textarea.js
TreeField.js
TypeField.js
UneditableField.js
UpperCaseField.js
UrlField.js
Copyright (c) 2008
Eric Abouaf
. All rights reserved.
Generated by
JsDoc Toolkit
1.4.1 on Wed, 07 May 2008 10:26:29 GMT.