MDBAutocomplete in react 18: default value from existing sta


Topic: MDBAutocomplete in react 18: default value from existing state

cariforef asked 2 years ago

Hello,

How can I set the value from a state like a default value or a local stored search value ?

Thanks. Didier


Krzysztof Wilk staff answered 2 years ago

Hi!

All options for the MDBInput component should also be available for the MDBAutocomplete one. You can use the defaultValue property or value along with onChange synthetic event :)


cariforef commented 2 years ago

Hy Krzysztof. I write my answer just above... :-) It does not work with value and onChange. And the DefaultValue is not changed


cariforef commented 2 years ago

Now, with the new version of mdbAutocomplet it works. Thanks.


cariforef answered 2 years ago

I can not add value property in the MDBAutocomplete. I get this error : The property does not exist in the type 'IntrinsicAttributes & Omit & { customContent?: ReactNode; dataFilter: (value: string) => any; ... 10 more ...; tag?: any; }'.

<MDBAutocomplete
        className="rounded-0"
        size="lg"
        id="inputSearch"
        value={value}
        name="inputSearch"
        threshold={6}
        noResults="Aucun résultat"
        label="Rechercher"
        onChange={(e) => setValue(e.target.value)}
        onSelect={handleSelect}
        displayValue={(value2: any) => {
          return value2.term.replace(/(<([^>]+)>)/gi, "").toLowerCase();
        }}
        dataFilter={autoComplete}
        itemContent={(result) => (
          <div
            dangerouslySetInnerHTML={{
              __html: result.term.toLowerCase(),
            }}
          />
        )}
      />

Krzysztof Wilk staff commented 2 years ago

Hi!

Could you create a simple snippet with that issue and full or simplified code just to show this issue? It's hard to say what's wrong with the fragment only. The Autocomplete component changed in the newest release so I think you should check the changes and correct your code using our updated documentation :)


Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Answered

Specification of the issue
  • User: Free
  • Premium support: No
  • Technology: MDB React
  • MDB Version: MDB5 5.1.0
  • Device: MAC
  • Browser: Chrome
  • OS: Mac OSX 15
  • Provided sample code: No
  • Provided link: No