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

How to set radeditor MaxTextLength property dynamically in Client code

3 Answers 121 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Chuck
Top achievements
Rank 1
Chuck asked on 21 Aug 2014, 06:57 PM
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

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 22 Aug 2014, 06:29 AM
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.
0
Chuck
Top achievements
Rank 1
answered on 22 Aug 2014, 02:49 PM
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);
});
},
0
Shinu
Top achievements
Rank 2
answered on 25 Aug 2014, 09:20 AM
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.
Tags
Editor
Asked by
Chuck
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Chuck
Top achievements
Rank 1
Share this question
or