How can I dynamically change the Max Length of a WebTextEditor via JavaScript? I have a drop down, and when that selection changes, I want to run a JavaScript function to set the max length of a corresponding WebTextEditor based upon the selection chosen. I have no problem with the initial function, but I don't know what I need to do to set the WebTextEditor's max length - there doesn't seem to be a client function like set_MaxLength.-Tom
Hello Tom,
Actually there is such function.
You can execute the following code on button click for example and check the results:
function setMaxLength() { var textEditor = $find("WebTextEditor1"); if (textEditor) { textEditor.set_maxLength(5); } }
function setMaxLength() {
var textEditor = $find("WebTextEditor1");
if (textEditor) {
textEditor.set_maxLength(5);
}
<ig:WebTextEditor ID="WebTextEditor1" runat="server" BackColor="#FFFF90"> </ig:WebTextEditor> <br /> <input id="btn2" type="button" value="Set Max Length" onclick="return setMaxLength()" />
<ig:WebTextEditor ID="WebTextEditor1" runat="server" BackColor="#FFFF90">
</ig:WebTextEditor>
<br />
<input id="btn2" type="button" value="Set Max Length" onclick="return setMaxLength()" />
Alex,
Well, this works partially.... Setting the max length work great via JavaScript when the user actually types into that field. The problem occurs when the user tries to paste a value into the field after the JS has set the max length. The paste is accepting the old prior max length that was set initially - not the new max length.
For instance, when the form comes up the default max length is set to 8. I then do something on the form that causes the JavaScript to run (in my case, I select a new value from a drop down list) and it sets the max length of the text field to 35. If I then physically type a value (say XYZ1234567890) into the text field it works fine; however, if I try to paste the value into the field it only shows and recognizes the first 8 characters (i.e. XYZ12345). It's as though for paste it is still retaining the old length value and/or something else needs to execute after the set_maxLength(35) to tell the field to also accept the 35 length for paste operations.
Any ideas on this? It's almost working except for the paste.
-Tom S
I have tested this but was unable to reproduce it – when max length is set with the JavaScript function the text in editor is as specified both when typing and when pasting.
I am attaching the sample used for testing.
Run it and paste/type some text in it with length greater than 10. You will see that on both actions the text length is reduced to 10.
Now press the button and repeat the above step – you will see that both on pasting and typing the text length is reduced to 5.
Test the sample and update me with the results.
Your code works fine; but for some reason I could not get it to work in my form. Maybe because of it being in a Master Page, or something else on the form. But I ended up getting around it by putting the items in an Update Panel, and using code behind via async to modify the length.
-Tom