Skip to content

Commit 4b2b066

Browse files
author
tanushah
committed
updated validation
1 parent 3bcbf23 commit 4b2b066

1 file changed

Lines changed: 8 additions & 26 deletions

File tree

Ginger/Ginger/ExternalConfigurations/VRTExternalConfigurationsPage.xaml.cs

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ private void SetControls()
6666

6767
if (!string.IsNullOrEmpty(_VRTConfiguration.ApiKey))
6868
{
69+
xAPIKeyTextBox.ValueTextBox.AddValidationRule(new ValidateEmptyValue("API Key cannot be empty"));
70+
6971
// Now that validation is attached, remove the binding so the real key won't show
7072
BindingOperations.ClearBinding(xAPIKeyTextBox.ValueTextBox, TextBox.TextProperty);
7173

@@ -100,36 +102,16 @@ private void CallVRTConfigPropertyChange()
100102

101103
private void xSaveButton_Click(object sender, RoutedEventArgs e)
102104
{
105+
// Preserve existing key unless user edited the field
103106
var apiKeyBox = xAPIKeyTextBox.ValueTextBox;
107+
string masked = apiKeyBox.Tag as string;
104108

105-
// Use existing mask marker if present; otherwise set a default
106-
string masked = apiKeyBox.Tag as string ?? "••••••••••••••••••••";
107-
108-
// If the user typed something (field differs from mask), treat it as an edit
109-
if (!string.Equals(apiKeyBox.Text, masked))
109+
if (!string.IsNullOrEmpty(masked) && !string.Equals(apiKeyBox.Text, masked))
110110
{
111-
112-
if (string.IsNullOrWhiteSpace(apiKeyBox.Text))
113-
{
114-
// Warn and do not overwrite stored key with empty value
115-
Reporter.ToLog(eLogLevel.WARN, "API Key cannot be empty");
116-
117-
// Restore the mask so we don’t reveal anything and keep UX consistent
118-
BindingOperations.ClearBinding(apiKeyBox, TextBox.TextProperty);
119-
apiKeyBox.Text = masked;
120-
apiKeyBox.Tag = masked;
121-
122-
return; // stop here; nothing to save for key
123-
}
124-
125-
// Assign new key only when user entered a non-empty value
126-
_VRTConfiguration.ApiKey = apiKeyBox.Text;
127-
128-
// Immediately re-mask after assigning to avoid exposure
129-
BindingOperations.ClearBinding(apiKeyBox, TextBox.TextProperty);
130-
apiKeyBox.Text = masked;
131-
apiKeyBox.Tag = masked;
111+
_VRTConfiguration.ApiKey = apiKeyBox.Text; // assign new key
112+
apiKeyBox.Text = masked; // re-mask after save
132113
}
114+
// else: field untouched or no mask in use -> keep existing _VRTConfiguration.ApiKey
133115

134116
WorkSpace.Instance.Solution.SolutionOperations.SaveSolution(true, SolutionGeneral.Solution.eSolutionItemToSave.LoggerConfiguration);
135117
}

0 commit comments

Comments
 (0)