Coder Social home page Coder Social logo

Comments (19)

iloveip avatar iloveip commented on May 30, 2024 1

Hi there,

Do you have any update on this?

from react-dadata-suggestions.

nobbynobbs avatar nobbynobbs commented on May 30, 2024

Hello.

I think for Final Form you could use the mutators for passing values from react-dadata-suggestion event handler into final form's state. Here is an example

from react-dadata-suggestions.

iloveip avatar iloveip commented on May 30, 2024

Thank you very much for your reply! Yes, it works, but the input itself is cleared now.

from react-dadata-suggestions.

nobbynobbs avatar nobbynobbs commented on May 30, 2024

Yes it's empty. You should somehow pass the value into the query attribute of Suggestions component. Sorry, I'm not familiar with Final Forms, so I can't help.
Also, I've just noticed the deprecation warning about mutators in my previous example, you should use form: mutators instead of mutators.

from react-dadata-suggestions.

nobbynobbs avatar nobbynobbs commented on May 30, 2024

@iloveip
Looks like it works
Also I fix deprecation warning.

from react-dadata-suggestions.

iloveip avatar iloveip commented on May 30, 2024

Thank you very much 🙏

from react-dadata-suggestions.

iloveip avatar iloveip commented on May 30, 2024

Hi there,

I've just noticed, that if you select an address (for example, with street), and then want to add a house, the input is cleared as soon as you start typing. (If you do the same with arrows up and down in the first place, everything is ok.) Is there any way to fix it?

from react-dadata-suggestions.

nobbynobbs avatar nobbynobbs commented on May 30, 2024

try

onChange={(event, value) => props.input.onChange({value: event})}

from react-dadata-suggestions.

iloveip avatar iloveip commented on May 30, 2024

Yes, now it works, thank you very much!

from react-dadata-suggestions.

iloveip avatar iloveip commented on May 30, 2024

I'm sorry, but I have one more question 🙏

In my example the suggestions list hides and shows on every key press as I type. Is there anyway to fix it?

from react-dadata-suggestions.

nobbynobbs avatar nobbynobbs commented on May 30, 2024

I doubt if it's possible in current implementation.

How it works: onChange event handler set the new value for form field, then this value passed into query prop of dadata component, and this causes componentWillReceiveProps handler fired, which clears suggestions list.

I'll think how to improve this use-case.

from react-dadata-suggestions.

iloveip avatar iloveip commented on May 30, 2024

Ok, thank you very much.

from react-dadata-suggestions.

nobbynobbs avatar nobbynobbs commented on May 30, 2024

So-so. I know how to fix your issue, but I don't know how to preserve current behavior for other cases.

from react-dadata-suggestions.

iloveip avatar iloveip commented on May 30, 2024

Could you please share your solution? Maybe I can fork your repository and fix it only for me (if other users don't have such problem).

from react-dadata-suggestions.

nobbynobbs avatar nobbynobbs commented on May 30, 2024

something like this

diff --git a/src/index.js b/src/index.js
index a8f8b50..9d2f3e6 100644
--- a/src/index.js
+++ b/src/index.js
@@ -74,12 +74,11 @@ class DadataSuggestions extends Component {
   }
 
   componentWillReceiveProps(nextProps) {
-    this.setState({
-      query: nextProps.query,
-      suggestions: [],
-      showSuggestions: false,
-      success: false,
-    });
+    const newQuery = nextProps.query;
+    const { query } = this.props;
+    if (newQuery != query) {
+      this.handleChange(newQuery);
+    }
   }
 
   componentWillUnmount() {
@@ -126,8 +125,7 @@ class DadataSuggestions extends Component {
     return searchWords;
   };
 
-  handleChange = (e) => {
-    const query = e.target.value;
+  handleChange = (query) => {
     const { deferRequestBy } = this.props;
 
     this.clearFetchTimeout();
@@ -258,7 +256,7 @@ class DadataSuggestions extends Component {
     return (
       <div className="suggestions-container">
         <QueryInput
-          onChange={ this.handleChange }
+          onChange={ e => this.handleChange(e.target.value) }
           placeholder={ this.props.placeholder }
           loading={ loading }
           query={ query }

from react-dadata-suggestions.

nobbynobbs avatar nobbynobbs commented on May 30, 2024

I've merged #25, please check release v1.1.0.

Just add new prop receivePropsBehaveLikeOnChange={true} to dadata component in your code. There is example based on your last link from codesandbox.

Looks like it works.

upd. 😆 🤣 no, it still doesn't work. Now select event is broken 🤔

from react-dadata-suggestions.

iloveip avatar iloveip commented on May 30, 2024

Ok. So I just wait? Or I can go ahead and fix you repo as you said above?

from react-dadata-suggestions.

nobbynobbs avatar nobbynobbs commented on May 30, 2024

@iloveip check v1.1.1 please, I hope it works. Link is the same as previous

from react-dadata-suggestions.

iloveip avatar iloveip commented on May 30, 2024

😃Thank you very much! Everything works great now!

from react-dadata-suggestions.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.