Bladeren bron

Improved validation handling for DynamicEditorForm

Kenric Nugteren 4 maanden geleden
bovenliggende
commit
194fb93494

+ 1 - 1
inabox.wpf/Dashboard/Editor/DynamicDashboardDataEditor.xaml.cs

@@ -75,7 +75,7 @@ public partial class DynamicDashboardDataEditor : UserControl, INotifyPropertyCh
         var item = QueryGrid.CreateItem();
         if (QueryGrid.EditItems([item]))
         {
-            QueryEditor.SaveItem(new CancelEventArgs(), validate: false);
+            QueryEditor.SaveItem(new CancelEventArgs());
             QueryGrid.DoChanged();
             QueryGrid.Refresh(false, true);
         }

+ 1 - 1
inabox.wpf/DynamicGrid/DynamicEditorForm/DynamicEditorForm.xaml.cs

@@ -191,7 +191,7 @@ public partial class DynamicEditorForm : ThemableChromelessWindow, IDynamicEdito
             }
         }
         if (Result == true)
-            Form.SaveItem(e, validate: false);
+            Form.SaveItem(e);
         SubPanelClosed?.Invoke(this);
     }
 

+ 7 - 2
inabox.wpf/DynamicGrid/DynamicEditorForm/EmbeddedDynamicEditorForm.xaml.cs

@@ -29,10 +29,12 @@ namespace InABox.DynamicGrid
         public event EventHandler OnChanged;
 
         private bool bChanged = false;
+        private bool _validated = false;
 
         public void DoChanged()
         {
             bChanged = true;
+            _validated = false;
             //OKButton.IsEnabled = true;
             //CancelButton.IsEnabled = true;
             OnChanged?.Invoke(this, EventArgs.Empty);
@@ -353,6 +355,8 @@ namespace InABox.DynamicGrid
                     "Validation Error");
                 return false;
             }
+
+            _validated = true;
             return true;
         }
 
@@ -388,14 +392,15 @@ namespace InABox.DynamicGrid
             //Close();
         }
 
-        public void SaveItem(CancelEventArgs e, bool validate = true)
+        public void SaveItem(CancelEventArgs e)
         {
-            if(validate && !Validate())
+            if(!_validated && !Validate())
             {
                 e.Cancel = true;
                 return;
             }
             OnSaveItem?.Invoke(this, e);
+            _validated = false;
         }
 
         public bool TryFindEditor(string columnname, [NotNullWhen(true)] out IDynamicEditorControl? editor)