Form: Limit Entry to MaxLength

2 Answers 19 Views
Form
Joel
Top achievements
Rank 3
Bronze
Iron
Iron
Joel asked on 27 Aug 2025, 04:49 PM | edited on 03 Sep 2025, 07:25 AM

How do I limit entry to just allow the MaxLength in the field?  Yes, I get an error when I enter 4000 characters in a field... but, why does it accept 4000 characters?  Is there a setting to limit/stop/truncate their entry?

            <TelerikForm Model="@ContextLink" Class="gsi-padding-10">
                <FormItems>
                    @if (IsDebug)
                    {
                        <FormItem Field="@nameof(ContextLink.Id)" LabelText="Id" Enabled="false" />
                    }

                    <FormItem Field="@nameof(ContextLink.Name)" LabelText="@nameof(ContextLink.Name)" Enabled="true" />
                    <FormItem Field="@nameof(ContextLink.Description)" LabelText="@nameof(ContextLink.Description)" Enabled="true" />
                    <FormItem Field="@nameof(ContextLink.RelativeUrl)" LabelText="@nameof(ContextLink.RelativeUrl)" Enabled="true" />
                    <FormItem Field="@nameof(ContextLink.ComponentFqn)" LabelText="@nameof(ContextLink.ComponentFqn)" Enabled="false" />

                </FormItems>
                <FormButtons />
            </TelerikForm>

        [MaxLength(50)]
        [Required]
        public string Name { get; set; }

2 Answers, 1 is accepted

Sort by
1
Ivan Danchev
Telerik team
answered on 31 Aug 2025, 10:42 AM

Hello Joel,

You can prevent the user from entering more than 4000 characters in the input by declaring the TextBox within the form and setting its MaxLength parameter to 4000. See this example: https://blazorrepl.telerik.com/GJuinvlk39f9PghW43 

Once the input reaches 4000 characters, further typing or pasting in the input is prevented. 

Regards,
Ivan Danchev
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Joel
Top achievements
Rank 3
Bronze
Iron
Iron
commented on 02 Sep 2025, 02:05 PM | edited

Okay, so I expected this to work from the annotations.  Is there a way to bind it to the property's maxlength property attribute instead of hard-coding this on the form?
0
Dimo
Telerik team
answered on 03 Sep 2025, 07:30 AM | edited on 03 Sep 2025, 07:46 AM

Hi Joel,

I deleted the other thread and the irrelevant posts here. MaxLength DataAnnotations validation is supported out-of-the-box, but you must enable Form validation.

Just to clarify, this is not a feature of the Form, but a feature of the DataAnnotationsValidator.

Regards,
Dimo
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
Form
Asked by
Joel
Top achievements
Rank 3
Bronze
Iron
Iron
Answers by
Ivan Danchev
Telerik team
Dimo
Telerik team
Share this question
or