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

cariforef priority asked 1 year ago


Hello,

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

Thanks. Didier


cariforef priority answered 1 year 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 1 year 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 1 year 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 priority commented 1 year ago

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


cariforef priority commented 1 year 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: Priority
  • Premium support: Yes
  • Technology: MDB React
  • MDB Version: MDB5 5.1.0
  • Device: MAC
  • Browser: Chrome
  • OS: Mac OSX 15
  • Provided sample code: No
  • Provided link: No