Skip to content

Firing onchange before painting on input #5544

Closed
@montyclt

Description

@montyclt

Hello everyone,

I have an input that I need that the user only writes in upper case.

I tried to do the following:

<input value="@Name" onchange="@ChangeName" />
void ChangeName(UIChangeEventArgs e)
{
    var value = (string)e.Value;

    Name = value.ToUpper();
}

The result:

The user writes in lowercase and when the user left focus, then the content transform to upper.

I tried too a hardcode value of Name property and left ChangeName method in blank like this:

<input class="form-control" value="@Name"/>
string Name = "Foo";

void ChangeName(UIChangeEventArgs e)
{
    // 
} 

I expected the original value of input return to "Foo", but when I leave the focus, the changed value stayed in the input.

Is possible make the value of input doesn't change if the value of value property doesn't change even if user type letters? (like readonly property)

Is possible to fire the onchange method before painting the input value to get in the input the value directly transformed while writing instead on lose focus? (like ReactJS)

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-blazorIncludes: Blazor, Razor Components

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions