I\'m attempting to use dojo for the first time, so this may be be obvious.
I have a very simple form with one textarea in it that needs to be filled in.
Based on your question, I guess you are using dojo 1.6
This is my ValidationTextarea
. It uses SimpleTextArea to support 'row' and 'cols' and ValidationTextBox for validation stuff.
The idea is similar to another answer just that in this case I don't define a templateString
for the widget.
dojo.provide('mynamespace.ValidationTextarea');
dojo.require("dijit.form.ValidationTextBox");
dojo.require("dijit.form.SimpleTextarea");
//ValidationTextarea: Validation class that hide the displayMessage and
//implement the validate method used by forms
dojo.declare("mynamespace.ValidationTextarea",[dijit.form.ValidationTextBox,dijit.form.SimpleTextarea], {
//int
// The maximum number of characters
maxLength: 255,
validate: function() {
if (arguments.length==0)
return this.validate(false);
return this.inherited(arguments);
},
onFocus: function() {
if (!this.isValid()) {
this.displayMessage(this.getErrorMessage());
}
},
onBlur: function() {
this.validate(false);
},
filter: function(/*String*/ value){
// Override TextBox.filter to deal with newlines... specifically (IIRC) this is for IE which writes newlines
// as \r\n instead of just \n
if(value){
value = value.replace(/\r/g,"");
}
return this.inherited(arguments);
},
displayMessage: function(/*String*/ message) {
}
});