This is a migrated thread and some comments may be shown as answers.

Can we Fix the MaxLength of Form Elements RadEditor

10 Answers 195 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Raaz
Top achievements
Rank 2
Raaz asked on 31 Jan 2013, 07:35 AM
Hello Telrik Support,
                               
Can we fix the max length of form elements like "Text Area", "Text Box"  in radedor.
Example: suppose i have taken one text box from "INSERT FROM ELEMENTS" option.
then user must only put 10 char in text box.


Please Help !!

Thanks 

10 Answers, 1 is accepted

Sort by
0
Rumen
Telerik team
answered on 04 Feb 2013, 11:31 AM
Hello,

You can use the maxlength attribute of the input element. You can access it with JavaScript with the following code: editor.get_contentArea().getElementsByTagName('input') where editor is a reference to the RadEditor and this will return a list with all inputs there so you can modify them as needed.

Kind regards,
Rumen
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Raaz
Top achievements
Rank 2
answered on 05 Feb 2013, 09:10 AM
Thanks for Reply,

               I have implement your solution it is working fine with TextBox , But it is working with TaxtArea field.

 function fixlength(editor, args) {
            var a = editor.get_contentArea().getElementsByTagName('input').length;
            var b = editor.get_contentArea().getElementsByTagName('input');
            for (var i = 0; i < a; i++) {
                if (b[i].type = "text") {
                    b[i].maxLength = 10;
                }
            }
           
var c = editor.get_contentArea().getElementsByTagName('textarea').length;
            var d = editor.get_contentArea().getElementsByTagName('textarea');
            for (var ii = 0; ii < d; ii++) {

                d[ii].maxlength = 10;
                
            }

        }



The Code showing in Italic is not working properly, Please help how we can fix the Length of Text Area.
0
Rumen
Telerik team
answered on 05 Feb 2013, 11:18 AM
Hello,

The maxlength attribute for textarea is supported by Firefox, Chroma and Safari. You can implement the following script to achieve your goal: Textarea Maxlength script.

Kind regards,
Rumen
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Raaz
Top achievements
Rank 2
answered on 06 Feb 2013, 10:12 AM
But i need in IE is this possible in IE for fix max length for Textarea??
0
Rumen
Telerik team
answered on 06 Feb 2013, 11:23 AM
Hello,

Yes, using the cross-browser solution provided in this article: Textarea Maxlength script.

Kind regards,
Rumen
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Raaz
Top achievements
Rank 2
answered on 06 Feb 2013, 12:39 PM
It is not working in Radeditor in IE....

function onchangee(editor, args) { 

            var a = editor.get_contentArea().getElementsByTagName('input').length;
            var b = editor.get_contentArea().getElementsByTagName('input');
            for (var i = 0; i < a; i++) {
                if (b[i].type = "text") {
                    b[i].maxLength = 10;
                }
            }
            var c = editor.get_contentArea().getElementsByTagName('textarea').length;
            var d = editor.get_contentArea().getElementsByTagName('textarea');
            for (var ii = 0; ii < c; ii++) {
                //d[ii].maxlength = 10;
                d[ii].onkeypress = "if(this.value.length > 10) return false;";
                
            }
}

I have create a java script function   onchangee, This function working fine for text box but not working for Text Area , 

Even OnkeyPress Event is working directly out side the Radeditor, But in RadEditor the Javascript function is not working....
<TEXTAREA onkeypress="if(this.value.length > 10) return false;"></TEXTAREA> 



PLEASE HELP!!!!


Your Solution is working fine out side of the Radeditor . But this javascript is not working on Inside's Textarea of rededitor
0
Rumen
Telerik team
answered on 07 Feb 2013, 04:54 PM
Hi,

The content area by default is an iframe. You should ensure that your code works in a standard editable iframe and it will work in RadEditor too.

The other option is to set the ContentAreaMode to DIV and test withing an editable DIV. Again if your code does not work, test with an editable DIV:

<div contenteditable="true" style="width:300px;height:300px;border: 1px solid red;">sample content</div>

Greetings,
Rumen
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Raaz
Top achievements
Rank 2
answered on 12 Feb 2013, 10:29 AM
Thanks For Reply,
                              My problem is not solve with this solution ,
My requirement is that i want to create a dynamic form with TextBox and TextArea only and some Write up. The textBox should have limit only 10 character and Textarea 200 but i am not able to restrict TextArea for 200 Char, Event TextBox has been fixed for 10 character.
Note- I need this solution  working on IE
Do you have any solution ??

Thanks in Advance!!
0
Rumen
Telerik team
answered on 14 Feb 2013, 04:01 PM
Hi,

Have you tried to implement the requested custom scenario with a standard editable DIV as suggested in my earlier post? All you need to do is to get the check the textareas length with the restricted length and if it exceeds to stop typing in them. This has nothing to do with RadEditor.

All the best,
Rumen
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Rumen
Telerik team
answered on 15 Feb 2013, 04:58 PM
Hello,

I tested the requested functionality in an editable iframe and I noticed that the browser does not execute the inline JavaScript code in the textarea element, which makes the implementation of this feature impossible until the browser developer do not enable it.

Best regards,
Rumen
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Editor
Asked by
Raaz
Top achievements
Rank 2
Answers by
Rumen
Telerik team
Raaz
Top achievements
Rank 2
Share this question
or