Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redux Form - Return current input value as string onChange

I'm trying to show a 'tick' next to my input when it contains at least 1 character to show a required field as being valid. The issue I have is that currently when I console.log(textEntered) each time the field changes I receive an object containing all the typed letters instead of a complete string. If I typed in 'hello' for example the log looks this (ignore the undefined):

enter image description here

Here is my Redux Field Component:

handleInput = (textEntered) => {
  console.log(textEntered);
  this.setState({ textEntered }, () => {
    if (this.state.textEntered.length) {
      this.setState({ completed: true });
    } else {
      this.setState({ completed: false });
    }
  });
}

render() {
  return (
    <Field
      name={this.props.placeholderText}
      component={TextInput}
      onChange={this.handleInput}
    />
  );
}

const TextInput = (field) => {
  return (
    <div className="drill-creation-input">
      <input
        {...field.input}
        type="input"
        onChange={e => field.input.onChange(e.target.value)}
      />

      <label htmlFor={field.input.name}>
        <span>{field.input.name}</span>
      </label>
    </div>
  );
};
like image 975
GuerillaRadio Avatar asked Jul 16 '26 19:07

GuerillaRadio


1 Answers

OnChange handler has the following signature (see docs)

onChange : (event, newValue, previousValue)

So to read the complete value, just define your handleInput like:

handleInput = (evnt, textEntered) => {
  console.log(textEntered);
  ...
}
like image 188
Dario Avatar answered Jul 18 '26 11:07

Dario