Unplanned
Last Updated: 28 Oct 2020 10:22 by ADMIN
René
Created on: 26 Oct 2020 09:02
Category: UI for Blazor
Type: Feature Request
1
Please add "NumberOfCharactersAllowed" Parameter to TextArea

There should be a counter displayed like this

"n:m" With n = currentNumberOfCharacters and m = allowedNumberOfCharacters.

5 comments
ADMIN
Svetoslav Dimitrov
Posted on: 28 Oct 2020 10:22

Hello René,

Thank you for your feedback, I agree that the MaxLength would be a nice feature to have. When we implement it I will make sure to pass your feedback to the dev team. 

Regards,
Svetoslav Dimitrov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

René
Posted on: 27 Oct 2020 07:03

Hello Svetoslav,

the first thing that came to my mind was clipping the text to the allowed number of characters upon key-up.  But then I realized that the downside to this would be that a pasted text could not be edited to reach the number of allowed characters (because the extra characters would be lost).

Disabling the component is not a good idea since the user could not make any corrections anymore.

So my favorite option would be that the number counter should turn red if max number of characters is exceeded!

A warning message which mimics the standard validation messages would be good as well but only if it allows for localization.

Regards,

René

ADMIN
Svetoslav Dimitrov
Posted on: 26 Oct 2020 15:00

Hello René,

I would like to use the occasion to ask for some feedback from you.

What would you expect to be the default behavior when the limit is reached - a warning message which mimics the standard validation messages, a red border around the component, or should it be disabled? 

Regarding the character counter (current/max), I have opened a separate Feature Request on your behalf, which you can see from this link. I have given your Vote for it and you can Follow it for email notifications on status updates.

Regards,
Svetoslav Dimitrov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

René
Posted on: 26 Oct 2020 11:09

Hello Svetoslav,

thanks for providing a workaround we can use until this feature is implemented.

Regards,

René

ADMIN
Svetoslav Dimitrov
Posted on: 26 Oct 2020 11:04

Hello Rene,

There are two approaches which you could use to handle this:

Input Validation

If you are using the TextArea in an EditForm you could benefit from the DataAnnotation attribute MaxLength(int maxLength, string ErrorMessage). An example of this approach could be seen in our Input Validation Article.

Using the TextArea outside EditForm

If you are using the TextArea outside EditForm you could create your own validation and utilize the ValueChanged event the component exposes. Below, I have added an example of how this could be done. Also, in this example, you could see a demo counter representing currentLength / maxLength. 

<TelerikTextArea Value="@TheValue" ValueChanged="@( (string i) => ValueChangedHandler(i))"></TelerikTextArea>
<div>
    <span>@TheValue.Length</span><span>/@MaxLength</span>
</div>
@if (!String.IsNullOrEmpty(WarningMessage))
{
    <div class="text-danger">
        @WarningMessage
    </div>
}

@code {
    public string TheValue { get; set; } = String.Empty;

    public string WarningMessage { get; set; }
    public int MaxLength { get; set; } = 10;

    void ValueChangedHandler(string input)
    {
        TheValue = MaximumLength(input, MaxLength);
    }

    public string MaximumLength(string value, int maxLength)
    {
        if (value.Length <= maxLength)
        {
            return value;
        }
        else
        {
            WarningMessage = $"The maximum length of the string should be {maxLength}";
            throw new Exception("My exception");
        }
    }
}

Additionally, you could wrap our component in a custom component for your application and pass the MaxLength as a [Parameter].

Regards,
Svetoslav Dimitrov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.