I tried the suggestion of Greg Hendee in his post here (http://www.telerik.com/community/forums/aspnet-mvc/numericinput/limit-number-of-characters-entered.aspx) but it doesn't solve my problem. Looking at the raw html i notice there are actually 3 controls that come into play for the NumericTextBox or IntegerTextBox. It is a div and two input tags inside the div.
I will describe what I'm doing and what I'm observing is happening in the event that I'm doing it incorrectly:
- I noticed that when I add an attribute to the .HtmlAttribute() method it puts said attribute on the div described above.
- I also noticed that when I add an attribute to the .InputHtmlAttribute() method it sometimes puts the attribute on both input controls and sometimes doesn't. This is where my problem is.
I am using the following code to set some attributes on my NumericTextBox and IntegerTextBox (I used both in the hopes that one would work):
<%: Html.Telerik().NumericTextBox()
.Name("TestNumeric")
.Value(3)
.MinValue(1)
.MaxValue(99)
.DecimalDigits(0)
.Spinners(false)
.InputHtmlAttributes(new { maxlength = "2", style="width: 25px;" })
.HtmlAttributes(new { maxlength = "2",style="width: 25px;" })
.ClientEvents(events => {events.OnChange("numericTextBoxChange");})
%>
<
br
/>
<%: Html.Telerik().IntegerTextBox()
.Name("TestInteger")
.Value(3)
.MinValue(1)
.MaxValue(99)
.Spinners(false)
.InputHtmlAttributes(new { maxlength = "2", style="width: 25px;" })
.HtmlAttributes(new { maxlength = "2",style="width: 25px;" })
.ClientEvents(events => {events.OnChange("integerTextBoxChange");})
%>
The problem is as you can see I'm specifying both the style attribute and the maxlength attribute but only the style attribute is put on both the input tags that are included in the div. It is putting the maxlength attribute on the input control that is set to display: none and I'm not sure how to set the other input tag with this attribute. Since it works for the style attribute, I assumed it would work for the maxlength attribute.
What am I doing wrong?
Thanks,
Paul
10 Answers, 1 is accepted
Indeed, this is a bug and we logged it for fixing. Until we do that, you can use the following work-around:
- remove the maxlength from the InputHtmlAttributes
- use the following script on the page:
<script type="text/javascript">
function initMaxWidth() {
$('#TestNumeric,#TestInteger')
.each(function() {
$(this).find('.t-input:first').attr('maxlength', 2);
});
}
</script>
<% Html.Telerik().ScriptRegistrar().OnDocumentReady(() => {%>initMaxWidth();<%}); %>
The issue will be addressed this week.
Greetings,
Alex Gyoshev
the Telerik team

Thanks,
Paul

Here's the code I'm using...
JavaScript:
<
script
type
=
"text/javascript"
>
function initMaxWidth(e) {
var children = $(e.currentTarget).children('.t-input');
$(children).each(function () {
$(this).attr('maxlength', 2);
});
}
</
script
>
Control Definition:
<%: Html.Telerik().NumericTextBox()
.Name("TestNumeric")
.Value(3)
.MinValue(1)
.MaxValue(99)
.DecimalDigits(0)
.Spinners(false)
.InputHtmlAttributes(new { style="width: 25px;" })
.HtmlAttributes(new { style="width: 25px;" })
.ClientEvents(events => {events.OnLoad("initMaxWidth");})
%>
<
br
/>
<%: Html.Telerik().IntegerTextBox()
.Name("TestInteger")
.Value(3)
.MinValue(1)
.MaxValue(99)
.Spinners(false)
.InputHtmlAttributes(new { style="width: 25px;" })
.HtmlAttributes(new { style="width: 25px;" })
.ClientEvents(events => {events.OnLoad("initMaxWidth");})
%>
In telerik.textbox.js, find the following code (line 34):
$('<input>', {
id: input.attr('id') + "-text",
name: input.attr('name') + "-text",
value: (inputValue || this.text),
'class': input.attr('class'),
style: input.attr('style')
})
... and add the maxlength attribute like this:
$('<input>', {
id: input.attr('id') + "-text",
name: input.attr('name') + "-text",
value: (inputValue || this.text),
'class': input.attr('class'),
style: input.attr('style'),
maxlength: input.attr('maxlength')
})
This should allow you to set the maxlength through the InputHtmlAttributes. It will be included in upcoming releases.
Kind regards,
Alex Gyoshev
the Telerik team

I did have one follow up question or two. I originally downloaded the Telerik Extensions for ASP.NET MVC from your site but had to download the codeplex version to get the "non-min" JS files. Should I keep the .min JS files in my project now that I have the uncompressed versions? Also what does the "Compress(true)" option truly do with the JS files because it doesn't seem to be converting them to .min versions on the fly like I had originally assumed.
Thanks,
Paul

I appreciate any help

I had to patch my telerik.textbox.js to make it work but I would like to get an "official" fixed version, so I don't overwrite the patch everytime there's a new version.
Cheers!
The issue will be fixed in the next official release of the Telerik Components for ASP.NET MVC.
Actually there will be some changes in the rendering which also will fix this issue.
Georgi Krustev
the Telerik team

Before this last version you used 't-grid-action' + 't-grid-edit/delete/whatever' for the grid buttons.
From this last update, the 't-grid-action' class is no more on the grid buttons... so all my $(this).closest('.t-grid-action') stopped working :(
This are the type changes on rendering you are planning for next version?... if so, please document them very well so I can fix my code to work with the newest versions...
All breaking changes will be documented in this help topic, once we release the components.
Georgi Krustev
the Telerik team