You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
New to MudBlazor (and Blazor) so this is probably just user error and not knowing the proper way to use all this. My end goal is to prepopulate a form, use form validation as intended, and not lose user input on validation errors. I can't find the secret settings to make my prepopulated field retain the value the user entered when it fails validation.
Click into the email field as the first interaction with the form
type an invalid email address
click outside the email field
as expected, the validation says it isn't a valid email address, and the value you typed remains.
Now, I want to prepopulate the field with a known value but allow users to change that value. So I bind the field:
Add to MudField: Text="@startValue" @code { string startValue = "start@value.com"; }
Running this code properly puts "start@value.com" in the email text field, and this passes validation. Great!
Now change the value in the text field to something that isn't valid, like
reallyLongAnnoyingEmailAddressThatNoOneCanRemember#domain.com
It properly flags the field as invalid, but the value I entered is replaced with the original value. The desired behavior would be to leave the user input for them to correct, as it does when the field isn't bound. I don't want it reverting to the prepopulated value.
I've tried all kinds of permutations, like binding the value instead of the text, or binding to a model, or not binding at all but setting the value manually:
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
New to MudBlazor (and Blazor) so this is probably just user error and not knowing the proper way to use all this. My end goal is to prepopulate a form, use form validation as intended, and not lose user input on validation errors. I can't find the secret settings to make my prepopulated field retain the value the user entered when it fails validation.
Using the sandbox example
as expected, the validation says it isn't a valid email address, and the value you typed remains.
Now, I want to prepopulate the field with a known value but allow users to change that value. So I bind the field:
Add to MudField: Text="@startValue"
@code { string startValue = "start@value.com"; }
Running this code properly puts "start@value.com" in the email text field, and this passes validation. Great!
Now change the value in the text field to something that isn't valid, like
reallyLongAnnoyingEmailAddressThatNoOneCanRemember#domain.com
It properly flags the field as invalid, but the value I entered is replaced with the original value. The desired behavior would be to leave the user input for them to correct, as it does when the field isn't bound. I don't want it reverting to the prepopulated value.
I've tried all kinds of permutations, like binding the value instead of the text, or binding to a model, or not binding at all but setting the value manually:
I haven't tried using an EditForm yet (about to), but it seems like this should work with MudForm.
Anyone come across this and/or know how to address is?
Beta Was this translation helpful? Give feedback.
All reactions