added: Textarea now supports maxlength attribute
This commit is contained in:
parent
6a10ae16d5
commit
3fc8c25025
2 changed files with 76 additions and 11 deletions
39
www/extras/yui-webgui/build/form/textarea.js
vendored
Normal file
39
www/extras/yui-webgui/build/form/textarea.js
vendored
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
|
||||
// Initialize namespace
|
||||
if (typeof WebGUI == "undefined") {
|
||||
var WebGUI = {};
|
||||
}
|
||||
if (typeof WebGUI.Form == "undefined") {
|
||||
WebGUI.Form = {};
|
||||
}
|
||||
WebGUI.Form.Textarea = {};
|
||||
|
||||
/****************************************************************************
|
||||
*
|
||||
* WebGUI.Form.Textarea
|
||||
* Scripts for the textarea control.
|
||||
*
|
||||
*/
|
||||
|
||||
WebGUI.Form.Textarea.checkMaxLength
|
||||
= function () {
|
||||
var maxLength = this.getAttribute('maxlength');
|
||||
var currentLength = this.value.length;
|
||||
if (currentLength > maxLength) {
|
||||
this.value = this.value.substring( 0, maxLength );
|
||||
alert( "This field can only contain " + maxLength + " characters" );
|
||||
}
|
||||
}
|
||||
|
||||
WebGUI.Form.Textarea.setMaxLength
|
||||
= function () {
|
||||
var x = document.getElementsByTagName('textarea');
|
||||
for ( var i = 0; i < x.length; i++ ) {
|
||||
if (x[i].getAttribute('maxlength')) {
|
||||
YAHOO.util.Event.addListener( x[i], "change", WebGUI.Form.Textarea.checkMaxLength );
|
||||
YAHOO.util.Event.addListener( x[i], "keyup", WebGUI.Form.Textarea.checkMaxLength );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue