5 Answers, 1 is accepted
Can you please elaborate a bit more on your scenario? The major issue about limiting RadRichTextBox content size is that this size varies a lot depending of the output format you may choose. Actually the size of the document cannot be determined when typing characters but only when the document is exported. We are looking forward to your response.
Greetings,
Mike
the Telerik team
I would like to perform Ui validation with radrichtextbox,not allowing/restricting the user while typing text(not more than 250 chratcters).output format is HTML (can add all sort things available in tool bar).could you please suggest me any other alternative.
Regards,
Nav
I am sorry but I need a bit more information about this case. What would you do with the Html document after the user edit it? Eg.g. save it in a database where you have restrictions in the size of the field to 250 chars? Or you simply need to restrict user not to enter too much text. I am asking this because these cases are very different. For example an Html document with 250 chars of text can actually become even several thousand of chars if the document is heavily formatted.
Anticipating your response.
All the best,
Mike
the Telerik team
I have been able to limit the input by using the on key press function and checking the TxtFormatProvider and HtmlFormatProvider. The problem I have is that when copy and paste is used, it can surpass that limit.
Thanks,
Mike
RadRichTextBox does not provide the functionality that will enable you to limit the text input's size out of the box. There are indeterministic cases that would arise if we were to implement it.
A good example is your case - the HTML output can grow if you change the style of the already inserted text. Thus, you can exceed the limits you have set without entering new symbols. What would you prefer to happen then - deny the applying of the new formatting or delete the text at the end?
Just a thought - don't you think that it will be better if you allowed users to exceed the limit while editing the text they input, and perform the validation when they try to leave/ save the field?
Otherwise, a workaround might be to handle the DocumentContentChanged event and undo the last change in the document if the size exceeds the limit. Something like:
private
void
radRichTextBox_DocumentContentChanged(
object
sender, EventArgs e)
{
TxtFormatProvider provider =
new
TxtFormatProvider();
while
(provider.Export(
this
.radRichTextBox.Document).Length
> MAX_LENGTH)
{
this
.radRichTextBox.Undo();
}
}
If you have any other questions, do not hesitate to contact us again. Greetings,
Iva
the Telerik team