question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Selected Text Not Appearing when Using Redux Form

See original GitHub issue

Version

React: 16.4.1 react-bootstrap-typeahead: 3.2.1 reactstrap: 6.3.1 redux-form: 7.4.2 redux: 4.0.0

Steps to reproduce

When the <TypeAhead /> compotent is nested in the <Field component form redux-form it causes an issue. The drop down list works perfectly, I select an item and the label doesn’t appear in the input field. The data is set in the Redux state however, so that part is working. I can see it with the Redux DevTools.

Below is the code that causes this issue:

<Field  name="jobSpec"
  component={this.renderTypeAheadField.bind(this)}
  placeholder="Please enter a collector name"
/>

renderTypeAheadField = ({ input, meta, ...rest }) => (
  <span>
    <Typeahead
      className={meta.touched && meta.error ? 'alert-danger' : ''}
      {...input}
      {...rest}
      labelKey="description"
      options={this.props.searchData}
      valueKey="id"
      clearButton
    />
    { meta.touched && meta.error && <FormFeedback tooltip >{meta.error}</FormFeedback>}
  </span>
);

Expected Behavior

I would expect the input field to show the selected text as it does when not used with Redux-Form.

Actual Behavior

When one makes a selection the selected item does not appear in the input field. However the selected item can be seen in the state using Redux DevTools, so the selection is working, the input field is just not populating.

image

image

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
blazestudios23commented, Aug 23, 2018

@ericgio Change selected as you specified above handled the issue of having to click twice.

The issue still persists when you delete a character, but I believe that is being caused by Redux emptying out the state. Which does make sense for Redux to do, however it’s not desirable in this case.

Best,

Andrew

1reaction
ericgiocommented, Aug 23, 2018

@blazestudios23: It sounds to me like Redux Form is updating state in a way that resets the component’s selections. As mentioned above, I’m unfamiliar with how Redux Form works, so I can’t provide much help here, only guess at the underlying issue. In any case, this doesn’t seem like a bug in the typeahead so I would recommend filing an issue with Redux Form or asking on StackOverflow, where others might be able to help.

One last note: Not sure if this will make a difference, but if this.props.jobSpec doesn’t exist, you should just return an empty array rather than an object with a blank description:

selected={this.props.jobSpec || []}
Read more comments on GitHub >

github_iconTop Results From Across the Web

value is not shown in the field when using redux form
I am using redux-form for the form. The form gets submitted but if page is refreshed I need to show that submitted data...
Read more >
Selecting Form Values Example - Redux Form
WARNING: Use this method sparingly, as it will cause your entire form to re-render every time one of the values you are selecting...
Read more >
Field - Redux Form
A callback that will be called whenever an onChange event is fired from the underlying input. If you call event.preventDefault() , the CHANGE...
Read more >
Field - Redux Form
This is the most flexible way to use <Field> , as it gives you complete control over how the input is rendered. It...
Read more >
Synchronous Validation Example - Redux Form
Notice the reused stateless function component used to render each field. It is important that this not be defined inline (in the render()...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found