Skip to content

Conversation

fcjoe-gis
Copy link

@fcjoe-gis fcjoe-gis commented Aug 22, 2025

Associated to #662

The FieldFormElementView and TextFormInputView call code to update based on if an error is found (missing Required data). When this is initially invoked the controls have not fully loaded and so the code to make these updates is not executed properly.

Code was added to tie in the Loaded event handler and when OnLoaded gets call the methods to update the view


//TextFormInputView.Maui

protected override void OnApplyTemplate()
{
	base.OnApplyTemplate();
	/* Removed from brevity */
	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();
}

In UpdateValidationState where the TextInput border is set to red when the ErrorsVisibility="Visible" property by also checking that condition

	private void UpdateValidationState()
	{
		var err = Element?.ValidationErrors;

		//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
  //replaced with above...    
     // if (err != null && err.Any() && Element?.IsEditable == true && _hadFocus)
// FieldForElementView
protected override void OnApplyTemplate()
{
	base.OnApplyTemplate();
	if (GetTemplateChild(FieldInputName) is ContentControl content)
	{
		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;
}

@fcjoe-gis
Copy link
Author

Also note that this comment description seems incorrect: FeatureFromView L:156

        /// <summary>
        /// Gets or sets the associated PopupManager which contains popup and sketch editor.
        /// </summary>
        public ValidationErrorVisibility ErrorsVisibility
        {
            get { return (ValidationErrorVisibility)GetValue(ErrorsVisibilityProperty); }
            set { SetValue(ErrorsVisibilityProperty, value); }
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant