I need to limit the number of characters user can enter in a text field. My approach is to build a custom TextField class as follows:
public class CTextField extends TextField {
attribute maxlen: Integer;
override attribute onKeyTyped: function(event:KeyEvent)= function(event:KeyEvent) {
if(text.length() >= maxlen)
{
event.source.consume();
}
};
}
TextField class should have an attribute such as maxlen that restricts number of characters allowed in the text box. This is a common data entry requirement. I shouldn't have to create a custom class to have this feature. This should be handled by TextField class.
public class CTextField extends TextField {
attribute maxlen: Integer;
override attribute onKeyTyped: function(event:KeyEvent)= function(event:KeyEvent) {
if(text.length() >= maxlen)
{
event.source.consume();
}
};
}
TextField class should have an attribute such as maxlen that restricts number of characters allowed in the text box. This is a common data entry requirement. I shouldn't have to create a custom class to have this feature. This should be handled by TextField class.