Skip to content
This repository has been archived by the owner on May 7, 2021. It is now read-only.

Commit

Permalink
Fix number inputs (patch)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorge Cuadra committed Sep 22, 2018
1 parent b760bf5 commit 0f54011
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 21 deletions.
31 changes: 13 additions & 18 deletions src/calculator/Calculator.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,7 @@ class Calculator extends React.Component {
onBlur={handleBlur}
onChange={handleChange}
outlined
type="number"
value={values.calories}
defaultValue={values.calories}
/>
{errors.calories && (
<TextFieldHelperText validationMsg persistent>
Expand All @@ -169,8 +168,7 @@ class Calculator extends React.Component {
onBlur={handleBlur}
onChange={handleChange}
outlined
type="number"
value={values.caloriesExtraForWorkoutDay}
defaultValue={values.caloriesExtraForWorkoutDay}
/>
{errors.caloriesExtraForWorkoutDay && (
<TextFieldHelperText validationMsg persistent>
Expand All @@ -181,34 +179,32 @@ class Calculator extends React.Component {
<GridCell span="4">
<TextField
className="mb-4 mr-4"
label="Fat % from calories"
name="fatCaloriesRatio"
label="Body weight (lbs)"
name="bodyWeight"
onBlur={handleBlur}
onChange={handleChange}
outlined
type="number"
value={values.fatCaloriesRatio}
defaultValue={values.bodyWeight}
/>
{errors.fatCaloriesRatio && (
{errors.bodyWeight && (
<TextFieldHelperText validationMsg persistent>
{errors.fatCaloriesRatio}
{errors.bodyWeight}
</TextFieldHelperText>
)}
</GridCell>
<GridCell span="4">
<TextField
className="mb-4 mr-4"
label="Body weight (lbs)"
name="bodyWeight"
label="Fat % from calories"
name="fatCaloriesRatio"
onBlur={handleBlur}
onChange={handleChange}
outlined
type="number"
value={values.bodyWeight}
defaultValue={values.fatCaloriesRatio}
/>
{errors.bodyWeight && (
{errors.fatCaloriesRatio && (
<TextFieldHelperText validationMsg persistent>
{errors.bodyWeight}
{errors.fatCaloriesRatio}
</TextFieldHelperText>
)}
</GridCell>
Expand All @@ -220,8 +216,7 @@ class Calculator extends React.Component {
onBlur={handleBlur}
onChange={handleChange}
outlined
type="number"
value={values.proteinGramsPerBodyWeightLb}
defaultValue={values.proteinGramsPerBodyWeightLb}
/>
{errors.proteinGramsPerBodyWeightLb && (
<TextFieldHelperText validationMsg persistent>
Expand Down
5 changes: 2 additions & 3 deletions src/recipes/RecipeForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,19 @@ const RecipeForm = ({ recipe = {}, onCancel, onSave }) => {
<Form>
<div className="flex flex-wrap p-4">
{RECIPE_ATTRIBUTES.map(function mapRecipeForm(
{ name, label, defaultValue },
{ name, label },
index,
) {
return (
<TextField
className="mb-4 mr-4"
key={index}
name={name}
value={values[name]}
defaultValue={values[name]}
onBlur={handleBlur}
outlined
label={label}
onChange={handleChange}
type={typeof defaultValue === 'string' ? 'text' : 'number'}
/>
);
})}
Expand Down

0 comments on commit 0f54011

Please sign in to comment.