Only change value of form onblur

This commit is contained in:
Casper Lamboo 2018-03-07 14:41:42 +01:00
parent d341cc28c9
commit c149667409

View File

@ -68,10 +68,15 @@ const _NumberField = ({ name, min, max, muiTheme: { palette }, ...props }, conte
value={_.get(context, name.toString())}
onChange={(event, value) => {
value = parseFloat(value);
if (typeof min === 'number') value = Math.max(value, min);
if (typeof max === 'number') value = Math.min(value, max);
context.onChange(name, value);
}}
onBlur={() => {
const value = _.get(context, name.toString());
let newValue = value;
if (typeof min === 'number') newValue = Math.max(newValue, min);
if (typeof max === 'number') newValue = Math.min(newValue, max);
if (newValue !== value) context.onChange(name, newValue);
}}
/>
);
_NumberField.contextTypes = contextTypes;