Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Normalize redux-form field value onBlur

Tags:

redux-form

How can I normalize the value of the redux-form field when onBlur is triggered. I tried the following, but it didn't seem to work:

const normalizeAmount = (node) => {
  const newValue = node.target.value;

  return `--${newValue}--`;
};

render() {
    const { handleSubmit, pristine, invalid, submitting, error, blur } = this.props;

return (
      <form onSubmit={handleSubmit(submit)}>
        <div name="form-container">
          <Field
            name="foo"
            component={CustomInput}
            onBlur={blurValue => blur(normalizeValue(blurValue))}
          /> 
          ...
);
like image 617
foobar Avatar asked Jun 30 '17 13:06

foobar


1 Answers

Solved this by moving onBlur to CustomInput component, where I add

return (
   <div>
    <input
      ...
      onBlur={value => props.input.onBlur(normalizeValue(value))}
    />
   </div>
);

And in the form component the field will just have:

<Field
   name="foo"
   component={CustomInput}
/> 
like image 177
foobar Avatar answered Nov 19 '22 13:11

foobar