public void ValidationSummaryPeerInvoke() { ValidationSummaryTestPage page = new ValidationSummaryTestPage(); this.TestPanel.Children.Add(page); ValidationSummary vs = page.validationSummary; this.EnqueueConditional(() => { return(page.validationSummary.Initialized); }); this.EnqueueCallback(() => { bool clicked = false; FocusingInvalidControlEventArgs eArgs = null; ValidationSummaryItem vsi = null; vs.FocusingInvalidControl += new EventHandler <FocusingInvalidControlEventArgs>(delegate(object o, FocusingInvalidControlEventArgs e) { clicked = true; eArgs = e; vsi = e.Item; }); ValidationSummaryAutomationPeer peer = new ValidationSummaryAutomationPeer(vs); Assert.IsNotNull(peer); ((IInvokeProvider)peer).Invoke(); Assert.IsFalse(clicked, "No error is selected, so the event should not fire"); ValidationSummaryItem newEsi = new ValidationSummaryItem(null, "test error", ValidationSummaryItemType.ObjectError, new ValidationSummaryItemSource("property name", page.nameTextBox), this); vs.Errors.Add(newEsi); vs.ErrorsListBoxInternal.SelectedItem = newEsi; ((IInvokeProvider)peer).Invoke(); Assert.IsTrue(clicked, "Invoking with a selected ESI triggers the event to fire"); Assert.AreEqual(newEsi, vsi, "The ESI should match the selected item"); Assert.AreEqual("property name", eArgs.Target.PropertyName, "The source should match the selected item"); }); EnqueueTestComplete(); }
/// <summary> /// OnErrorClicked is invoked when an error in the ValidationSummary is clicked, via either the mouse or keyboard. /// </summary> /// <param name="e">The FocusingInvalidControlEventArgs for the event.</param> protected virtual void OnFocusingInvalidControl(FocusingInvalidControlEventArgs e) { EventHandler <FocusingInvalidControlEventArgs> handler = this.FocusingInvalidControl; if (handler != null) { handler(this, e); } }
private void ExecuteClick(object sender) { ListBox lb = sender as ListBox; if (lb != null) { ValidationSummaryItem vsi = lb.SelectedItem as ValidationSummaryItem; if (vsi != null && this.FocusControlsOnClick) { int idx; // Ensure the currently selected item source is valid if (vsi.Sources.Count == 0) { // Clear the current ESI source if the ESI has none, such as when the ESI has changed this._currentValidationSummaryItemSource = null; } else { // If the current ESI source is not part of the current set, select the first one by default. idx = FindMatchingErrorSource(vsi.Sources, this._currentValidationSummaryItemSource); if (idx < 0) { this._currentValidationSummaryItemSource = vsi.Sources[0]; } } // Raise the event FocusingInvalidControlEventArgs e = new FocusingInvalidControlEventArgs(vsi, this._currentValidationSummaryItemSource); this.OnFocusingInvalidControl(e); #if OPENSILVER // Raise the AutomationPeer event ValidationSummaryAutomationPeer peer = ValidationSummaryAutomationPeer.FromElement(this) as ValidationSummaryAutomationPeer; if (peer != null && AutomationPeer.ListenerExists(AutomationEvents.InvokePatternOnInvoked)) { peer.RaiseAutomationEvent(AutomationEvents.InvokePatternOnInvoked); } #endif // Focus the target, which will usually be the current ESI source or the overwritten one if (!e.Handled && e.Target != null && e.Target.Control != null) { e.Target.Control.Focus(); } // Update currently selected item, but only if there are multiple ESI sources. if (vsi.Sources.Count > 0) { idx = FindMatchingErrorSource(vsi.Sources, e.Target); idx = idx < 0 ? 0 : ++idx % vsi.Sources.Count; this._currentValidationSummaryItemSource = vsi.Sources[idx]; } } } }
public void FocusingInvalidControl() { ValidationSummaryTestPage page = new ValidationSummaryTestPage(); this.TestPanel.Children.Add(page); ValidationSummary vs = page.validationSummary; this.EnqueueConditional(() => { return(page.validationSummary.Initialized); }); this.EnqueueCallback(() => { page.nameTextBox.Text = "ABCDEFG!@#$"; Assert.AreEqual(1, vs.Errors.Count); bool clicked = false; // Setup the delegate to capture the event vs.ErrorsListBoxInternal.SelectedIndex = 0; FocusingInvalidControlEventArgs eArgs = null; ValidationSummaryItem vsi = null; vs.FocusingInvalidControl += new EventHandler <FocusingInvalidControlEventArgs>(delegate(object o, FocusingInvalidControlEventArgs e) { clicked = true; eArgs = e; vsi = e.Item; }); // Simulate a click on the first item vs.ExecuteClickInternal(); Assert.IsTrue(clicked); Assert.IsNotNull(eArgs); Assert.IsNotNull(vsi); Assert.AreEqual("Name", vsi.Sources[0].PropertyName); // Set the flag to false, clicks should no longer occur, as it only affects focus vs.FocusControlsOnClick = false; clicked = false; eArgs = null; vs.ExecuteClickInternal(); Assert.IsFalse(clicked); Assert.IsNull(eArgs); }); EnqueueTestComplete(); }
public void ErrorClickedSelectedItem() { ValidationSummaryTestPage page = new ValidationSummaryTestPage(); this.TestPanel.Children.Add(page); ValidationSummary vs = page.validationSummary; this.EnqueueConditional(() => { return(page.validationSummary.Initialized); }); this.EnqueueCallback(() => { page.nameTextBox.Text = "ABCDEFG!@#$"; Assert.AreEqual(1, vs.Errors.Count); ValidationSummaryItem newVsi = new ValidationSummaryItem("test error", null, ValidationSummaryItemType.ObjectError, new ValidationSummaryItemSource("property name", page.nameTextBox), this); vs.Errors.Add(newVsi); bool clicked = false; // Setup the delegate to capture the event vs.ErrorsListBoxInternal.SelectedItem = newVsi; FocusingInvalidControlEventArgs eArgs = null; ValidationSummaryItem vsi = null; vs.FocusingInvalidControl += new EventHandler <FocusingInvalidControlEventArgs>(delegate(object o, FocusingInvalidControlEventArgs e) { clicked = true; eArgs = e; vsi = e.Item; }); // Simulate a click on the first item vs.ExecuteClickInternal(); Assert.IsTrue(clicked); Assert.IsNotNull(vsi); Assert.AreEqual("test error", vsi.Message); Assert.AreEqual(ValidationSummaryItemType.ObjectError, vsi.ItemType); Assert.AreEqual(this, vsi.Context); Assert.AreEqual(page.nameTextBox, vsi.Sources[0].Control); Assert.AreEqual("property name", vsi.Sources[0].PropertyName); }); EnqueueTestComplete(); }
private void vldSum_FocusingInvalidControl(object sender, FocusingInvalidControlEventArgs e) { }