Page 1 of 1

Preventing content insertion

Posted: Tue Jul 03, 2012 2:40 pm
by neon096
I'm trying to restrict a user from entering more than 2000 characters for a given element. Whereby the content the user is trying to insert is ignored. I'm currently looking at the AuthoringListenerAdapter beforeContentInsert method and I can count the text content but I'm struggling to prevent the component from adding the text.

The other way I've thought of is to change and use the contentInserted method and then manually code for the removing of the inserted text. Which could get quite messy if there are nested nodes.

Can you please advise what the best approach will be?

Re: Preventing content insertion

Posted: Tue Jul 03, 2012 2:45 pm
by Radu
Hi Neil,

We have an API method like:

AuthorDocumentController.setDocumentFilter(AuthorDocumentFilter)

and in the filter you can overwrite the method:

AuthorDocumentFilter.insertText(AuthorDocumentFilterBypass, int, String)

You can check which AuthorNode contains the offset:

AuthorDocumentController.getNodeAtOffset(int)

and then if that node is a certain node you can look at its start and end offsets to see how much content it has inside.

If it has too much content you can stop delegating to the "AuthorDocumentFilterBypass" the event.

Regards,
Radu