Some question about RadzenTextBox and RadzenValidators

Hi everyone,

In RequiredValidatorPage in demo I have added @oninput to stop writing chars when length is 10.

<RadzenTextBox style="display: block" Name="FirstName" @bind-Value="model.FirstName" @oninput="@(args => OnInput(args.Value.ToString()))" />

void OnInput(string value)
{
model.FirstName = value.Substring(0,value.Length < 10 ? value.Length : 10);
}

a) it's not working, but it doing other action for example change line for this "model.FirstName = value.Substring(0,value.Length < 10 ? value.Length : 10); " for this "model.FirstName = value.Replace("h","");" work. I think there is some comparator inside code that not detect changes in model.FirstName.

b) I'd like form validate RadzenTextBox on each char input on RadzenTextBox. Is it posible? Is there any method in RadzenTemplateForm to force validate fields or some field?

c) @onclick:stopPropagation="true" and/or @onclick:preventDefault="true" work on RadzenTextBox?

thank you and good job!

Hi @ctnet,

I don't understand a).

Validating on each char isn't supported. Does the Blazor built-in validation support that? Asking because the Radzen validators rely a lot on the built-in validation.

@onclick:stopPropagation="true" and/or @onclick:preventDefault="true" should probably work as they are output as additional attributes.

dear @korchev,
thank you so much for your quick answer

a) sorry for my very poor explanation,
I don't know how to explain problem easily. If you take your demo code and in RequiredValidatorPage change RadzenTextBox with Name="FirstName" for this one:

<RadzenTextBox style="display: block" Name="FirstName" 7@bind-Value="model.FirstName" @oninput="@(args => OnInput(args.Value.ToString()))" />

and use

void OnInput(string value)
{
model.FirstName = value.Replace("h","");
}

everytime you write every time you write the h will be deleted. So far, perfect, OnInput works correctly
but if you change OnInput for the following method

void OnInput(string value)
{
model.FirstName = value.Substring(0,value.Length < 10 ? value.Length : 10);
}

Whose purpose is to avoid writing more than 10 characters, it does not work, you can write all the characters you want and it will not stop when you exceed 10 characters. model.FirstName changes within the OnInput method and only has the first 10 characters of value, but something happens somewhere in the radzen library code that does not update the value of the input tag and so you can type more than 10 characters.
I hope this time I could explain the problem better.

b) yes there is a method inside Blazor built-in validation: EditContext.Validate(), but How can I access EdtiContext in RadzenTemplateForm ?

thank you in advanced

Hi @ctnet,

The RadzenTextBox has a MaxLength property which you can use to limit the number of characters. It renders as the maxlength attribute of the <input> element.

We will expose the EditContext property of the RadzenTemplateForm in the next release.