Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed function responsible for trimming leading zeros. #87

Merged
merged 3 commits into from
Nov 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions cogboard-webapp/src/components/BoardForm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,14 @@ const BoardForm = ({ onSubmit, renderActions, boardId, ...initialFormValues }) =
const validationSchema = createValidationSchema(boardId, boards);
const {values, handleChange, handleSubmit, errors} = useFormData(initialFormValues, validationSchema, true);

const handleNumberInput = (event) => {
const { target: { value } } = event;

event.target.value = trimLeadingZeros(value);
};

return (
<form onSubmit={handleSubmit(onSubmit)} novalidate="novalidate">
<form onSubmit={handleSubmit(onSubmit)} noValidate="novalidate">
<StyledFieldset component="fieldset">
<TextField
onChange={handleChange('title')}
Expand All @@ -28,7 +34,7 @@ const BoardForm = ({ onSubmit, renderActions, boardId, ...initialFormValues }) =
label="Title"
margin="normal"
value={values.title}
error={errors.title}
error={errors.title !== undefined}
helperText={
<StyledValidationMessages
messages={errors.title}
Expand All @@ -38,7 +44,7 @@ const BoardForm = ({ onSubmit, renderActions, boardId, ...initialFormValues }) =
/>
<NumberInput
onChange={handleChange('columns')}
onInput={trimLeadingZeros}
onInput={handleNumberInput}
id="columns"
InputLabelProps={{
shrink: true
Expand All @@ -47,7 +53,8 @@ const BoardForm = ({ onSubmit, renderActions, boardId, ...initialFormValues }) =
label="Columns"
margin="normal"
value={values.columns}
error={errors.columns}
error={errors.columns !== undefined}
FormHelperTextProps={{ component: 'div' }}
helperText={
<StyledValidationMessages
messages={errors.columns}
Expand All @@ -71,15 +78,16 @@ const BoardForm = ({ onSubmit, renderActions, boardId, ...initialFormValues }) =
{values.autoSwitch &&
<NumberInput
onChange={handleChange('switchInterval')}
onInput={trimLeadingZeros}
onInput={handleNumberInput}
id="switchInterval"
InputLabelProps={{
shrink: true
}}
label="Switch interval [s]"
margin="normal"
value={values.switchInterval}
error={errors.switchInterval}
error={errors.switchInterval !== undefined}
FormHelperTextProps={{ component: 'div' }}
helperText={
<StyledValidationMessages
messages={errors.switchInterval}
Expand Down
7 changes: 1 addition & 6 deletions cogboard-webapp/src/helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,4 @@ export const parseYupErrors = (errors) => {
return result;
};

export const trimLeadingZeros = (event) => {
const inputValue = event.target.value;
const parsedValue = parseInt(inputValue);

event.target.value = parsedValue.toString();
};
export const trimLeadingZeros = (inputValue) => String(parseInt(inputValue));