@@ -78,16 +78,17 @@ document.addEventListener("DOMContentLoaded", () => {
7878
7979 function validateForm ( showMessages : boolean = false ) : ValidationMessage [ ] {
8080 const errors : ValidationMessage [ ] = [ ] ;
81+ const warnings : ValidationMessage [ ] = [ ] ;
8182 const inputApiKey = elements . inputFields . apiKey . value . trim ( ) ;
8283 const outputApiKey = elements . inputFields . apiKeyOutput . value . trim ( ) ;
8384
8485 // Clear existing validation messages and styles
8586 document . querySelectorAll ( ".validation-message" ) . forEach ( ( el ) => {
8687 el . textContent = "" ;
87- el . classList . remove ( "show" ) ;
88+ el . classList . remove ( "show" , "warning" ) ;
8889 } ) ;
8990 document . querySelectorAll ( "input" ) . forEach ( ( input ) => {
90- input . classList . remove ( "error" ) ;
91+ input . classList . remove ( "error" , "warning" ) ;
9192 } ) ;
9293
9394 // Required field validation - only show errors for touched fields
@@ -111,21 +112,47 @@ document.addEventListener("DOMContentLoaded", () => {
111112 // API key validation - only when both fields have values
112113 if ( inputApiKey && outputApiKey ) {
113114 if ( inputApiKey === outputApiKey ) {
114- errors . push ( {
115+ warnings . push ( {
115116 field : "apiKey" ,
116- message : "Input and Output API Keys must be different" ,
117+ message :
118+ "Input and Output API Keys are same. Copy Data Assets will be disabled." ,
117119 } ) ;
118- errors . push ( {
120+ warnings . push ( {
119121 field : "apiKeyOutput" ,
120- message : "Input and Output API Keys must be different" ,
122+ message :
123+ "Input and Output API Keys are same. Copy Data Assets will be disabled." ,
121124 } ) ;
122125 if (
123126 showMessages ||
124127 ( touchedFields . has ( "apiKey" ) &&
125128 touchedFields . has ( "apiKeyOutput" ) )
126129 ) {
127- elements . inputFields . apiKey . classList . add ( "error" ) ;
128- elements . inputFields . apiKeyOutput . classList . add ( "error" ) ;
130+ elements . inputFields . apiKey . classList . add ( "warning" ) ;
131+ elements . inputFields . apiKeyOutput . classList . add ( "warning" ) ;
132+ // Disable and uncheck the copyDataAssets checkbox
133+ elements . inputFields . copyDataAssets . checked = false ;
134+ elements . inputFields . copyDataAssets . disabled = true ;
135+ const label = document . querySelector (
136+ `label[for="copyDataAssets"]`
137+ ) ;
138+ if ( label ) {
139+ label . classList . add ( "disabled-text" ) ;
140+ }
141+ } else {
142+ elements . inputFields . apiKey . classList . remove ( "warning" ) ;
143+ elements . inputFields . apiKeyOutput . classList . remove (
144+ "warning"
145+ ) ;
146+
147+ // Enable the copyDataAssets checkbox when API keys are different
148+ elements . inputFields . copyDataAssets . disabled = false ;
149+
150+ const label = document . querySelector (
151+ `label[for="copyDataAssets"]`
152+ ) ;
153+ if ( label ) {
154+ label . classList . remove ( "disabled-text" ) ;
155+ }
129156 }
130157 }
131158 }
@@ -141,9 +168,43 @@ document.addEventListener("DOMContentLoaded", () => {
141168 }
142169 } ) ;
143170
171+ // Section to display warnings
172+ warnings . forEach ( ( warning ) => {
173+ const messageEl = document . getElementById (
174+ `${ warning . field } -validation`
175+ ) ;
176+ if (
177+ messageEl &&
178+ ( showMessages || touchedFields . has ( warning . field ) )
179+ ) {
180+ messageEl . textContent = warning . message ;
181+ messageEl . classList . add ( "show" ) ;
182+ messageEl . classList . add ( "warning" ) ; // Add warning class to message
183+ }
184+ } ) ;
185+
144186 return errors ;
145187 }
146188
189+ function updateCopyDataAssetsState ( ) : void {
190+ const inputApiKey = elements . inputFields . apiKey . value . trim ( ) ;
191+ const outputApiKey = elements . inputFields . apiKeyOutput . value . trim ( ) ;
192+
193+ // Enable checkbox if API keys are different or empty
194+ const shouldEnable =
195+ ! inputApiKey || ! outputApiKey || inputApiKey !== outputApiKey ;
196+
197+ elements . inputFields . copyDataAssets . disabled = ! shouldEnable ;
198+ const label = document . querySelector ( `label[for="copyDataAssets"]` ) ;
199+ if ( label ) {
200+ if ( shouldEnable ) {
201+ label . classList . remove ( "disabled-text" ) ;
202+ } else {
203+ label . classList . add ( "disabled-text" ) ;
204+ }
205+ }
206+ }
207+
147208 // Add validation styles
148209 const style = document . createElement ( "style" ) ;
149210 style . textContent = `
@@ -173,22 +234,50 @@ document.addEventListener("DOMContentLoaded", () => {
173234 box-shadow: 0 0 0 1px #dc2626 !important;
174235 outline: none;
175236 }
237+
238+ input.warning {
239+ border-color: #f59e0b !important;
240+ background-color: #fffbeb !important;
241+ transition: all 0.2s ease-in-out;
242+ }
243+
244+ input.warning:focus {
245+ border-color: #f59e0b !important;
246+ box-shadow: 0 0 0 1px #f59e0b !important;
247+ outline: none;
248+ }
249+
250+ .validation-message.warning {
251+ color: #f59e0b;
252+ }
253+
254+ .disabled-text {
255+ color: #dc2626 !important;
256+ opacity: 0.7;
257+ }
176258 ` ;
177259 document . head . appendChild ( style ) ;
178260
179261 // Real-time validation
180262 Object . entries ( elements . inputFields ) . forEach ( ( [ key , input ] ) => {
181263 input . addEventListener ( "blur" , ( ) => {
182- // Mark field as touched when user leaves it
183264 touchedFields . add ( key ) ;
184265 const errors = validateForm ( false ) ;
185266 elements . submitButton . disabled = errors . length > 0 ;
267+ // Add updateCopyDataAssetsState call for API key fields
268+ if ( key === "apiKey" || key === "apiKeyOutput" ) {
269+ updateCopyDataAssetsState ( ) ;
270+ }
186271 } ) ;
187272
188273 input . addEventListener ( "input" , ( ) => {
189274 if ( touchedFields . has ( key ) ) {
190275 const errors = validateForm ( false ) ;
191276 elements . submitButton . disabled = errors . length > 0 ;
277+ // Add updateCopyDataAssetsState call for API key fields
278+ if ( key === "apiKey" || key === "apiKeyOutput" ) {
279+ updateCopyDataAssetsState ( ) ;
280+ }
192281 }
193282 } ) ;
194283 } ) ;
0 commit comments