Skip to content

Commit

Permalink
Merge pull request scandipwa#5247 from AleksandrsKondratjevs/issue-5243
Browse files Browse the repository at this point in the history
issue-5243 - Fix types for validation checkbox fields
  • Loading branch information
AleksandrsKondratjevs authored Oct 28, 2022
2 parents 878984b + aabb7be commit 9d52635
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 7 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
2 changes: 1 addition & 1 deletion packages/scandipwa/src/util/Form/Extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ export const getFieldsData = <AsObject extends boolean = false>(
: field.value;

const dateValue = field.getAttribute('data-date');
const formattedValue = dateValue ? getDateValue(dateValue) : value || '';
const formattedValue = dateValue ? getDateValue(dateValue) : value;

if (!excludeEmpty || value) {
output.push({
Expand Down
2 changes: 1 addition & 1 deletion packages/scandipwa/src/util/Form/Form.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ export type GetFieldsData<AsObject extends boolean = false> = AsObject extends t

export type FieldValue<
T = unknown, isUnknownValue = true,
> = isUnknownValue extends true ? string | number | boolean | Date : T;
> = isUnknownValue extends true ? string | number | boolean | undefined | Date : T;
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 9d52635

Please sign in to comment.