You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/uui-base/lib/mixins/FormControlMixin.ts
+79-10Lines changed: 79 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -5,15 +5,18 @@ import { UUIFormControlEvent } from '../events';
5
5
6
6
typeConstructor<T={}>=new(...args: any[])=>T;
7
7
8
+
typeNativeFormControlElement=HTMLInputElement;// Eventually use a specific interface or list multiple options like appending these types: ... | HTMLTextAreaElement | HTMLSelectElement
9
+
8
10
// TODO: make it possible to define FormDataEntryValue type.
* @param {FlagTypes} flagKey the type of validation.
211
-
* @param {method} getMessage method to retrieve relevant message. Is executed every time the validator is re-executed.
217
+
* @param {method} getMessageMethod method to retrieve relevant message. Is executed every time the validator is re-executed.
212
218
* @param {method} checkMethod method to determine if this validator should invalidate this form control. Return true if this should prevent submission.
213
219
*/
214
220
protectedaddValidator(
215
221
flagKey: FlagTypes,
216
222
getMessageMethod: ()=>String,
217
223
checkMethod: ()=>boolean
218
-
){
219
-
this._validators.push({
224
+
): Validator{
225
+
constobj={
220
226
flagKey: flagKey,
221
-
getMessage: getMessageMethod,
227
+
getMessageMethod: getMessageMethod,
222
228
checkMethod: checkMethod,
223
-
});
229
+
};
230
+
this._validators.push(obj);
231
+
returnobj;
232
+
}
233
+
234
+
protectedremoveValidator(validator: Validator){
235
+
constindex=this._validators.indexOf(validator);
236
+
if(index!==-1){
237
+
this._validators.splice(index,1);
238
+
}
239
+
}
240
+
241
+
/**
242
+
* @method addFormControlElement
243
+
* @description Important notice if adding a native form control then ensure that its value and thereby validity is updated when value is changed from the outside.
244
+
* @param element {NativeFormControlElement} - element to validate and include as part of this form association.
// Loop through custom validators, currently its intentional to have them overwritten native validity. but might need to be reconsidered (This current way enables to overwrite with custom messages)
0 commit comments