i want to take uppercase only even if i am entering lowercase it should convert in uppercase in text field in mudblazor.
<MudTextField For="@(() => AddEditItemModel.HSNSAC)"
@bind-Value="AddEditItemModel.HSNSAC"
Label="@_localizer["SAC"]"
MaxLength="3">
</MudTextField>
i tried to call through @onclick method and tried to handle with method, but the issue is that method is getting called.
<MudTextField For="@(() => AddEditItemModel.HSNSAC)"
@bind-Value="AddEditItemModel.HSNSAC"
Label="@_localizer["SAC"]" MaxLength="3"
@oninput="ConvertToUppercase"
</MudTextField>
2
Answers
You need to use
Value
andValueChanged
instead of@bind-Value
if you want to add custom logic for when the value changes.The changed value will be passed to the handler method that you assign to
ValueChanged
.Since
Value
is a property of typeT
you need to define the it in the component e.g.T="string"
. docsAnother tip: You can also set
Immediate="true"
if you want it to change to uppercase on each input.MudBlazor Snippet
Alternatively, you can use the
Text
andTextChanged
where the type used for those arestring
soT
does not need to be declared.To convert text to uppercase as the user types you need to do the following: