Skip to content

Commit

Permalink
Fix types for validation checkbox fields
Browse files Browse the repository at this point in the history
  • Loading branch information
AleksandrsKondratjevs committed Oct 26, 2022
1 parent e47c570 commit 866c34f
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
3 changes: 3 additions & 0 deletions packages/scandipwa/mosaic.jsconfig
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
],
"Pages/*": [
"src/pages/*"
],
"Src/*": [
"src/*"
]
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ S extends ProductContainerState = ProductContainerState,
* @param errors
* @returns {boolean}
*/
filterAddToCartFileErrors(errors: Array<{ type: string; value: string }>): boolean {
filterAddToCartFileErrors(errors: Array<{ type: string; value: string | boolean }>): boolean {
return errors ? errors.filter((e) => (e.type === 'file' && e.value !== '')).length !== 0 : false;
}

Expand Down
3 changes: 1 addition & 2 deletions packages/scandipwa/src/util/Validator/Validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,7 @@ export const validateGroup = (DOM: HTMLElement, rule?: ValidationRule): true | V
} = field;

const fieldType = tagName.toLowerCase() === FieldType.TEXTAREA ? FieldType.TEXTAREA : type;
// eslint-disable-next-line max-len
const fieldValue = fieldType === (FieldType.CHECKBOX || fieldType === FieldType.RADIO) && field.checked ? '' : value;
const fieldValue = fieldType === FieldType.CHECKBOX || fieldType === FieldType.RADIO ? field.checked : value;

output.values?.push({ name, value: fieldValue, type: fieldType });

Expand Down
4 changes: 2 additions & 2 deletions packages/scandipwa/src/util/Validator/Validator.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface ValidationRule {
inputType?: string;
selector?: string;
match?: string
| ((value: string | Record<string, string>[] | undefined) => boolean)
| ((value: string | Record<string, string | boolean>[] | undefined) => boolean)
// eslint-disable-next-line @typescript-eslint/no-explicit-any
| ((...args: any[]) => boolean | string);
range?: { min?: number; max?: number; showLengthError?: boolean };
Expand All @@ -32,7 +32,7 @@ export interface ValidationOutput {
export interface ValidationDOMOutput {
values?: {
name: string;
value: string;
value: string | boolean;
type: string;
}[];
errorFields?: unknown[];
Expand Down

0 comments on commit 866c34f

Please sign in to comment.