MicrosoftEdge / MicrosoftEdge/WebView2Feedback

Validated event not fired properly

Open
#2,992 1 comment 0 reactions 1 assignee View on GitHub

@bradp0721 is already working on this.

Since Nov 28, 2022.

bug tracked
Dominant language
PowerShell
Stars
526
Forks
67
PR merge metrics
No merged PRs in 30d

Description

If the WebView2 control loses focus it should raise the "Validated" event. However, this will only happen if WebView2 has gained focus by pressing the TAB key. If it gains focus by clicking the mouse, the "Validated" event will not be fired on subsequent loss of focus.
Microsoft.Web.WebView2 version 1.0.1418.22
Below is the source code to reproduce the problem.

How to reproduce the problem:

  1. Click on textbox1
  2. Click on textbox2 (textbox2 gets focus)
  3. Click on webview2 (webview2 gets focus)
  4. Click on textbox1 (textbox1 gets focus)
  5. Click on textbox2 (textbox2 gets focus)

In the console output you will see:

textbox1 validated
textbox2 validated
textbox1 validated

However, the expected result should be:

textbox1 validated
textbox2 validated
webView2 validated
textbox1 validated

However, if you use the TAB key, everything works as expected:

  1. Click on textbox1
  2. Press the TAB key (textbox2 gets focus)
  3. Press the TAB key (webview2 gets focus)
  4. Click on textbox1 (textbox1 gets focus)
  5. Press the TAB key (textbox2 gets focus)

In the console output you will see:

textbox1 validated
textbox2 validated
webView2 validated
textbox1 validated

Source code to reproduce the problem. Create new WinForms project, edit form1.cs.

 public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            var textbox1 = new TextBox();
            textbox1.TabIndex = 0;
            textbox1.Parent = this;
            textbox1.Validated += (_, _) => Console.WriteLine("textbox1 validated");

            var textbox2 = new TextBox();
            textbox1.TabIndex = 1;
            textbox2.Parent = this;
            textbox2.Left = 200;
            textbox2.Validated += (_, _) => Console.WriteLine("textbox2 validated");

            var webView2 = new WebView2();
            textbox1.TabIndex = 2;
            webView2.Top = 30;
            webView2.Width = Width;
            webView2.Height = Height-30;
            webView2.Parent = this;
            webView2.Source = new Uri("https://www.google.com");
            webView2.Validated += (_, _) => Console.WriteLine("webView2 validated");
        }
    }

To see the console, change OutputType from "WinExe" to "Exe"

 <Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net6.0-windows</TargetFramework>
    <Nullable>enable</Nullable>
    <UseWindowsForms>true</UseWindowsForms>
    <ImplicitUsings>enable</ImplicitUsings>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.Web.WebView2" Version="1.0.1418.22" />
  </ItemGroup>

</Project>

AB#44144440

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.