Skip to content

Commit

Permalink
style: whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
kristian4res committed Apr 8, 2024
1 parent d7687df commit 6d05c44
Showing 1 changed file with 81 additions and 80 deletions.
161 changes: 81 additions & 80 deletions src/form/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const Form = (props: CustomFormProps) => {
}
return errors;
},
{} as { [key in UserFormKeys]: string[] }
{} as { [key in UserFormKeys]: string[] }
);
if (isEmpty(formErrors)) {
return true;
Expand Down Expand Up @@ -100,85 +100,86 @@ const Form = (props: CustomFormProps) => {
};
});
};
type Validators = { name: string, validators: ((val: string, name: string, formData: { [key: string]: string }) => string[])[] };
const registerInput = ({ name, validators }: Validators) => {
setFormState(state => {
return {
...state,
validators: {
...state.validators,
[name]: validators || []
},
// clear any errors
errors: {
...state.errors,
[name]: []
}
};
});
type Validators = { name: string, validators: ((val: string, name: string, formData: { [key: string]: string }) => string[])[] };
const registerInput = ({ name, validators }: Validators) => {
setFormState(state => {
return {
...state,
validators: {
...state.validators,
[name]: validators || []
},
// clear any errors
errors: {
...state.errors,
[name]: []
}
};
});
// returning unregister method

Check failure on line 119 in src/form/index.tsx

View workflow job for this annotation

GitHub Actions / lint (20.x)

Expected indentation of 8 spaces but found 6
return () => {
setFormState(state => {
// copy state to avoid mutating it
const { data, errors, validators: currentValidators } = { ...state };
// clear field data, validations and errors
delete data[name];
delete errors[name];
delete currentValidators[name];
return {
data,
errors,
validators: currentValidators
};
});
};
};
const providerValue = {
errors: formState.errors,
data: formState.data,
setFieldValue,
registerInput
};
const errorList = [];
for (const key in formState.errors) {
if (formState.errors[key].length) {
errorList.push({ fieldID: key, errorMessage: formState.errors[key] });
}
}
return (
<Provider value={providerValue}>
{
errorList.length > 0 &&
<div aria-labelledby="error-summary-title" role="alert"
className="ons-panel panel--error">
<div className="ons-panel__header">
<h2 id="error-summary-title" data-qa="error-header" className="ons-panel__title ons-u-fs-r--b">There
are {errorList.length} problems with your answer</h2>
</div>
<div className="ons-panel__body">
<ol className="ons-list">
{
errorList.map(({ fieldID, errorMessage }) => {
return (
<li key={fieldID} className="ons-list__item">
<a href={`#${fieldID}`}
className="ons-list__link ons-js-inpagelink">{errorMessage[0]}</a>
</li>
);
})
}
</ol>
</div>
</div>
}
<form
onSubmit={onSubmit}
onReset={onReset}
className={"ons-u-mt-m"}
>
{props.children}
</form>
</Provider>
);
return () => {
setFormState(state => {
// copy state to avoid mutating it
const { data, errors, validators: currentValidators } = { ...state };
// clear field data, validations and errors
delete data[name];
delete errors[name];
delete currentValidators[name];
return {
data,
errors,
validators: currentValidators
};
});
};
};
const providerValue = {
errors: formState.errors,
data: formState.data,
setFieldValue,
registerInput
};
const errorList = [];
for (const key in formState.errors) {
if (formState.errors[key].length) {
errorList.push({ fieldID: key, errorMessage: formState.errors[key] });
}
}
return (
<Provider value={providerValue}>
{
errorList.length > 0 &&
<div aria-labelledby="error-summary-title" role="alert"
className="ons-panel panel--error">
<div className="ons-panel__header">
<h2 id="error-summary-title" data-qa="error-header" className="ons-panel__title ons-u-fs-r--b">
There are {errorList.length} problems with your answer
</h2>
</div>
<div className="ons-panel__body">
<ol className="ons-list">
{
errorList.map(({ fieldID, errorMessage }) => {
return (
<li key={fieldID} className="ons-list__item">
<a href={`#${fieldID}`}
className="ons-list__link ons-js-inpagelink">{errorMessage[0]}</a>
</li>
);
})
}
</ol>
</div>
</div>
}
<form
onSubmit={onSubmit}
onReset={onReset}
className={"ons-u-mt-m"}
>
{props.children}
</form>
</Provider>
);
};
export default Form;

0 comments on commit 6d05c44

Please sign in to comment.