diff --git a/src/Toolkit/Toolkit/UI/Controls/FeatureForm/FieldFormElementView.Maui.cs b/src/Toolkit/Toolkit/UI/Controls/FeatureForm/FieldFormElementView.Maui.cs index edb49b5be..2b665c437 100644 --- a/src/Toolkit/Toolkit/UI/Controls/FeatureForm/FieldFormElementView.Maui.cs +++ b/src/Toolkit/Toolkit/UI/Controls/FeatureForm/FieldFormElementView.Maui.cs @@ -131,8 +131,17 @@ protected override void OnApplyTemplate() { content.ContentTemplate = new FieldTemplateSelector(this); } + + // JH: If UpdateErrorMessages is called before the FieldFormElementView is Loaded it fails + Loaded += OnLoaded; UpdateErrorMessages(); } + + private void OnLoaded(object? sender, EventArgs e) + { + UpdateErrorMessages(); + Loaded -= OnLoaded; + } } } #endif \ No newline at end of file diff --git a/src/Toolkit/Toolkit/UI/Controls/FeatureForm/FieldFormElementView.cs b/src/Toolkit/Toolkit/UI/Controls/FeatureForm/FieldFormElementView.cs index 79e52c550..cfe598c36 100644 --- a/src/Toolkit/Toolkit/UI/Controls/FeatureForm/FieldFormElementView.cs +++ b/src/Toolkit/Toolkit/UI/Controls/FeatureForm/FieldFormElementView.cs @@ -178,6 +178,9 @@ private void UpdateErrorMessages() } if (GetTemplateChild("ErrorLabel") is TextBlock tb) { + // JH: If the control is not loaded yet, updating error message will fail. + if ( !IsLoaded ) return; + tb.Text = errMessage ?? string.Empty; bool showError = false; if (!string.IsNullOrEmpty(errMessage) && (_hadFocus || FeatureFormView.GetFeatureFormViewParent(this)?.ShouldShowError() == true)) diff --git a/src/Toolkit/Toolkit/UI/Controls/FeatureForm/TextFormInputView.Maui.cs b/src/Toolkit/Toolkit/UI/Controls/FeatureForm/TextFormInputView.Maui.cs index 8bfb2078b..4fff737f0 100644 --- a/src/Toolkit/Toolkit/UI/Controls/FeatureForm/TextFormInputView.Maui.cs +++ b/src/Toolkit/Toolkit/UI/Controls/FeatureForm/TextFormInputView.Maui.cs @@ -119,6 +119,14 @@ protected override void OnApplyTemplate() button.Clicked += BarcodeButton_Clicked; } ConfigureTextBox(); + + //JH: Same issue as in FieldFormElement, the first time UpdateValidationState is called Element is null + Loaded += OnLoaded; + UpdateValidationState(); + } + + private void OnLoaded(object? sender, EventArgs e) + { UpdateValidationState(); } diff --git a/src/Toolkit/Toolkit/UI/Controls/FeatureForm/TextFormInputView.cs b/src/Toolkit/Toolkit/UI/Controls/FeatureForm/TextFormInputView.cs index 4a45e1ec0..969cb7b69 100644 --- a/src/Toolkit/Toolkit/UI/Controls/FeatureForm/TextFormInputView.cs +++ b/src/Toolkit/Toolkit/UI/Controls/FeatureForm/TextFormInputView.cs @@ -364,11 +364,15 @@ private void Element_PropertyChanged(object? sender, System.ComponentModel.Prope this.Dispatch(UpdateValidationState); } } - + private void UpdateValidationState() { var err = Element?.ValidationErrors; - if (err != null && err.Any() && Element?.IsEditable == true && _hadFocus) + + //JH: Add a check to see if the ErrorsVisibility is set to true, not only if _hadFocus is true + bool shouldShowError = (FeatureFormView.GetFeatureFormViewParent(this)?.ShouldShowError() ?? false) || _hadFocus; + + if (err != null && err.Any() && Element?.IsEditable == true && shouldShowError) { #if MAUI if (GetTemplateChild("ErrorBorder") is Border border)