How to set radeditor MaxTextLength property dynamically in Client code

4 posts, 0 answers
  1. Chuck
    Chuck avatar
    18 posts
    Member since:
    Apr 2014

    Posted 21 Aug 2014 Link to this post

    Hello,

    Is there any client API or mechanism that can be used to configure RADEditor MaxTextLength property dynamically in the Client code (JavaScript)? I need to control maximum number of characters should be allowed to enter into editor (single instance) depending on context option (jquery) selected by the user. For example, 200 characters for legend but 1000 characters for reference etc.

    Thanks,
    Chuck
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 22 Aug 2014 in reply to Chuck Link to this post

    Hi Chuck,

    Please try the below JavaScript code snippet to achieve your scenario.

    JavaScript:
    function pageLoad() {
        var editor = $find("<%=reditorDemo.ClientID%>");
        editor.set_maxTextLength(10);
    }

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Chuck
    Chuck avatar
    18 posts
    Member since:
    Apr 2014

    Posted 22 Aug 2014 Link to this post

    Hi,

    It does not take effect if I try to change the maxTextLength using set_maxTextLength() other than in the pageLoad(). 

    Thanks,
    Chuck

    Here is my code snippet:

    launchEditor: function (title, source) {
    $("#modal-dialog").dialog({
    "title": title,
    modal: true,
    autoOpen: false,
    resize: "auto",
    draggable: true,
    width: 600,
    height: 380,
    open: function (event, ui) { $('.ui-dialog-titlebar-close').show(); },
    position: 'top',
    resizable: false,
    zIndex: 99990
    });
    $("#modal-dialog").dialog('open');

    //configure max content size limit according to the metadata field type
    var maxLength = 20000; //default for "Legend", "Footnote", "Source", "Internal Notes"
    if (title == "Graphic Display Name") {
    maxLength = 64;
    } else if (title == "Title") {
    maxLength = 500;
    } else if (title == "Instructions" || title == "Permission Notes") {
    maxLength = 4000;
    } else if (title == "Version Comment") {
    maxLength = 2000;
    }

    _editor.set_maxTextLength(maxLength);
    _editor.set_html(source());

    $(".ui-widget-overlay").click(function () {
    $("#modal-dialog").dialog('close');
    var data = _editor.get_html();
    //fixed RADEditor bug of converting <br /> to <BR> tag
    data = data.replace(/<br\s*>/gi, "<br />");
    //check if the content is really empty without any whitespace and linebreak
    if (__getValueWithoutSpacesFromString(data).length == 0) {
    data = '';
    }
    source(data);
    });
    },
  5. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 25 Aug 2014 in reply to Chuck Link to this post

    Hi Chuck,

    Unfortunately I couldn't replicate the issue at my end. Please try the below sample code snippet which works fine at my end.

    ASPX:
    <telerik:RadEditor ID="reditorDemo" runat="server">
    </telerik:RadEditor>
    <telerik:RadButton ID="rbtnChangeLength" runat="server" Text="Change Length" AutoPostBack="false"
        OnClientClicked="changeLength">
    </telerik:RadButton>

    JavaScript:
    function pageLoad() {
        var editor = $find("<%=reditorDemo.ClientID%>");
        editor.set_maxTextLength(10);
    }
    function changeLength(sender, args) {
        var editor = $find("<%=reditorDemo.ClientID%>");
        editor.set_maxTextLength(5);
    }

    Thanks,
    Shinu.
Back to Top