View Full Version : How to restrict maximum length for html editor field

12 Dec 2012, 4:26 AM

I am trying to restrict my html editor field to maximum 1000 character , but there is no config option in htmleditor field. And also want to make htmleditor field as mandatory field, for that also no config is available.

Is it possible to restrict the htmleditor , and can it be a mandatory field?

If it is than please help me in this, please share some code if possible so that i can understand how to do it.

Any help will be appreciated.


14 Dec 2012, 6:07 AM
The issue you will have is to strip out the html for the maximum character limit.

Reason for no allowBlank is because HtmlEditor extends Component

14 Dec 2012, 6:37 AM
Hi Mitchell,
Thanks for reply.

My issue is that , I want to restrict entering more than 1000 character in htmleditor. The character can be anything may be it's html tag , white space etc.I want to validate the htmleditor for that , if the entered character is more than 1000 than the htmleditor field should be validation fail and it will show the red color border on the field. It just similar like maxNumer : 1000 in textarea or textfield.

And if some one does not write anything on the textarea it should show a mandatory message like field is required with the red color border.

How can it be in extjs? Please suggest me the best approach in extjs.


14 Dec 2012, 8:33 AM
Listen for keydown and then cancel it if it has over 1000 chars

14 Dec 2012, 9:28 AM
I didn't know you could cancel a keydown by listening to the event. Just return false to cancel the keydown? That's handy to know, actually.

*Also, you might put a listener on the change event in case they copy/paste > 1000 characters using the mouse and context menu paste?

14 Dec 2012, 10:11 AM
Thanks for reply Slemmon,
Any key event is not listening the events because there is no configuration in htmleditor like enable enableKeyEvents.
Key events are not working for the htmleditor.

16 Dec 2012, 11:42 PM
Hi ,

How to create a function like allowBlank for fields like textarea, textfield etc. Since the htmleditor does not support the allowblank configuration . I have to show the red color border when the form is submitted on clicking the save button.Can we create a custom config function to make a htmleditor mandatory field. So that if the field validation is false than form should be invalid.