How do I reset the position of a floating AutoComplete input


Topic: How do I reset the position of a floating AutoComplete input label when nulling the Input value through Javascript?

ikan_nak pro premium priority asked 1 months ago

Expected behavior

I have an input with an a floating label and Autocomplete component that I need to be able to set to empty through Javascript. I want the label to return to the center of the component after the reset.

Actual behavior

When doing "autocompleteInput.value = null", the value gets set to empty, but the floating label stays aligned with the border of the component instead of returning to the center of the input, as shown in below snippet.

I have tried using the below code as part of my reset function, and it does seem to work, but it requires changing internal properties, which I'd rather avoid doing.

    mdb.Autocomplete.getOrCreateInstance(autocompleteContainer)._isOpen = true;
    mdb.Autocomplete.getOrCreateInstance(autocompleteContainer).close();
    mdb.Autocomplete.getOrCreateInstance(autocompleteContainer)._isOpen = false;

Is there a more correct way of emptying an AutoComplete component such that it has a null value and the label back in the center?

Resources (screenshots, code snippets etc.)

https://mdbootstrap.com/snippets/standard/ikan_nak/6300117#html-tab-view


Kamila Pieńkowska staff answered 1 months ago

Here is a snippet for you: https://mdbootstrap.com/snippets/standard/kpienkowska/6301099


ikan_nak pro premium priority commented 1 months ago

Thanks, this worked.


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: Pro
  • Premium support: Yes
  • Technology: MDB Standard
  • MDB Version: MDB5 7.2.0
  • Device: Desktop computer
  • Browser: Edge
  • OS: Windows 11
  • Provided sample code: No
  • Provided link: Yes
Tags