Field validation #176
Replies: 2 comments
-
I think it will be custom built functionality I will try something out and give you feedback. |
Beta Was this translation helpful? Give feedback.
-
@GrahameArmitage Update. AssumptionsI assume that you know how to expose your validations to the Razor Code bool isValid(object SomeObj) => SomeObjValidator.Validate(SomeObj).IsValid; and I assume you know how to use the Now to the messI created a custom class; class FocusInput
{
public string Name { get; set; }
public dynamic Element { get; set; }
public ValueTaskAwaiter Focus() =>
Element switch
{
InputText => ((InputText)Element).Element.Value.FocusAsync().GetAwaiter(),
InputDate<DateTime> => ((InputDate<DateTime>)Element).Element.Value.FocusAsync().GetAwaiter(),
InputSelect<string> => ((InputSelect<string>)Element).Element.Value.FocusAsync().GetAwaiter(),
_ => ((ElementReference)Element).FocusAsync().GetAwaiter(),
};
} Then I created a List to work as a container for all my inputs. nameof(model.Username) this is just the easy part. bool isValid(object SomeObj) => SomeObjValidator.Validate(SomeObj).IsValid;
if (!IsValid(model.Password))
focusInputs.FirstOrDefault(x => x.Name = nameof(model.Password)).Focus(); This is not the cleanest way to do it nor the best. |
Beta Was this translation helpful? Give feedback.
-
Hello there.
Please can someone help me out?
I have a form with a button that performs validation and it works fine. I'm after a way of intercepting validation when a field is exited so I can return focus back to the field if it's invalid. The default way is the OnFieldChanged() event is fired, does the validation (including a call to the api for uniqueness), highlights the field red if invalid and goes to the next field.
Any help would be most appreciated.
Cheers,
Grahame
Beta Was this translation helpful? Give feedback.
All reactions