Skip to content

Commit

Permalink
Changed function responsible for trimming leading zeros. (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bartłomiej Jackowiak authored Nov 7, 2019
1 parent 316c99a commit ad6dd59
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
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));

0 comments on commit ad6dd59

Please sign in to comment.