Holiday Notice: Support will be provided on a limited scale from December 24th, 2024, to January 2nd, 2025. Happy holidays and a wonderful New Year!


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

cariforef free 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


cariforef free 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 :)


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 free 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 free commented 2 years ago

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



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

  • ForumUser: 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