I have an Asp.net MVC/Razor app using the Infragistics JQuery controls and I would like to limit the number of characters entered in a igTextEditor. On my page I have
@(Html.Infragistics().TextEditorFor(m=>m.Name).ID("assemblyNameEditor").ValidatorOptions(m=>m.OnBlur(true).OnSubmit(true).FormSubmit(true).KeepFocus(ValidatorKeepFocus.Once)).Required(true)
and then down in my JQuery script section I have
$("#assemblyNameEditor").igTextEditor("option", "maxLength", 10);
when looking at the rendered page I see that the maxlength attribute was not added. SO then I just used simple jquery to add the maxlength attribute ...
$("#assemblyNameEditor").attr("maxLength", 10);
which rendered fine but for some reason was still not limiting the characters.
So then I was I hoping I could at least decorate my model with DataAnnotations such as
[StringLength(20, ErrorMessage = "Must be under 20 characters")]
and have have validation catch it on submit, but that didn't work either.
Not sure what else to try??
Hello Mlangowski,
Have you tried setting the maxlength of the texteditor something like below, I was able to limit the characters in the editor using the following code
@(Html.Infragistics().TextEditor()
.ID("textEditor")
.MaxLength(10)
.Width(200)
.NullText("Enter Text")
.Render())
Please let me know if you have any further questions regarding this matter.
Umm... MaxLength ?? TextEditor does not have a MaxLength method defined. Is this an extension method?
I am using version v4.0.30319 of Infragistics.Web.Mvc.
Hi,
The igEditor is a widget, which implements all functionality and can accept any option of any extended editor. All extended editors like igMaskEditor, igCurrencyEditor, etc. are nothing more but wrappers, which do the only one thing: they set value of the "type" option for its base igEditor widget.
All extended editors were designed for purpose of clarity and documentation related to different functionality defined by the "type" option, and those extended editors target only explicit javascript usage.
Note: jquery does not support inheritance and each widget is final. It means, that if application created instance of igTextEditor, then it can not "typecast" it to igEditor in order to get/set options or call methods. Same for case when igEditor is created. Application can not be treated as igTextEditor. Application should use exact name of widget in initializer.
In case of Mvc, all editors instantiate the single igEditor and set its type option.
The maxLength can be set on server and on client as well. Below are examples for 3 possible scenarios. You may copy paste those lines into any (mvc) sample and check how it runs.
1. The Mvc creates TextEditor, sets its MaxLength on server and later changes maxLength on client.
<%= Html.Infragistics().TextEditor("Editor1").MaxLength(10).Render()%><input type="button" value="change1" onclick="$('#Editor1').igEditor('option', 'maxLength', 3)" />
2. That mimics Mvc #1 exactly, and shows what happens on client. The javascript creates igEditor, sets its maxLength in initializer and later changes maxLength.
<span id="Editor2"></span><script type="text/javascript"> $(function () { $('#Editor2').igEditor({ type:'text', maxLength: 10 }); });</script><input type="button" value="change2" onclick="$('#Editor2').igEditor('option', 'maxLength', 3)" />
3. The javascript creates igTextEditor, sets its maxLength in initializer and later changes maxLength.
<span id="Editor3"></span><script type="text/javascript"> $(function () { $('#Editor3').igTextEditor({ maxLength: 10 }); });</script><input type="button" value="change3" onclick="$('#Editor3').igTextEditor('option', 'maxLength', 3)" />
You can set the maxlength for the text editor using the igEditor function intead of igTextEditor
Here is the code snippet
$('#textEditor').igEditor('option', 'maxLength', 3);
I have attached the view I have used to test this issue. I am using NetAdvatage for JQuery 2012 Vol1 with the latest service release 2023.
Also, I was not able to set the maxlength at run time. It looks like a bug to me. I am currently doing further testing and will update you by the end of the day Monday.