0

I am using SurveyJS to quickly build a survey form in React/Redux.

I implemented a custom widget using a React component for Google Maps Places Autocomplete. My problem is that once suggestions appear and the field state changes, the contents of all the other survey fields get cleared. Is there a way to prevent it?

Here's what I did to integrate React Places Autocomplete into the survey as a custom widget.

1
  • Hello! I am one of SurveyJS contributor. I would suggest you to check our README github.com/surveyjs/widgets Add your own custom widget section. It contains an example of custom widget with usefull comments plnkr.co/edit/HdnYE5?p=preview. Probably the bug is related to "two way" binding. Commented Mar 27, 2018 at 11:30

1 Answer 1

-1

As soon as you select the Address field the onChange is called, the component loses the state for the other fields.

"setState() will always lead to a re-render unless shouldComponentUpdate() returns false. If mutable objects are being used and conditional rendering logic cannot be implemented in shouldComponentUpdate(), calling setState() only when the new state differs from the previous state will avoid unnecessary re-renders." from reactjs.org

Sign up to request clarification or add additional context in comments.

2 Comments

Could you please explain a little bit more?
Thanks, @Kix_g, I ended up wrapping the PlacesAutocomplete with another component which I then used as the custom widget for SurveyJS. setState() on the wrapper component re-renders PlacesAutocomplete but did not affect the rest of the form, which helped preserve content of the other 'normal' fields. I'd give you an upvote but I do not have enough reputation to be able to do so.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.