Can we Fix the MaxLength of Form Elements RadEditor

11 posts, 0 answers
  1. Raaz
    Raaz avatar
    11 posts
    Member since:
    Jan 2013

    Posted 31 Jan 2013 Link to this post

    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 
  2. Rumen
    Admin
    Rumen avatar
    12851 posts

    Posted 04 Feb 2013 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Raaz
    Raaz avatar
    11 posts
    Member since:
    Jan 2013

    Posted 05 Feb 2013 Link to this post

    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.
  5. Rumen
    Admin
    Rumen avatar
    12851 posts

    Posted 05 Feb 2013 Link to this post

    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.
  6. Raaz
    Raaz avatar
    11 posts
    Member since:
    Jan 2013

    Posted 06 Feb 2013 Link to this post

    But i need in IE is this possible in IE for fix max length for Textarea??
  7. Rumen
    Admin
    Rumen avatar
    12851 posts

    Posted 06 Feb 2013 Link to this post

    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.
  8. Raaz
    Raaz avatar
    11 posts
    Member since:
    Jan 2013

    Posted 06 Feb 2013 Link to this post

    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
  9. Rumen
    Admin
    Rumen avatar
    12851 posts

    Posted 07 Feb 2013 Link to this post

    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.
  10. Raaz
    Raaz avatar
    11 posts
    Member since:
    Jan 2013

    Posted 12 Feb 2013 Link to this post

    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!!
  11. Rumen
    Admin
    Rumen avatar
    12851 posts

    Posted 14 Feb 2013 Link to this post

    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.
  12. Rumen
    Admin
    Rumen avatar
    12851 posts

    Posted 15 Feb 2013 Link to this post

    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017