[BUG] select setValue does not accept numbers


Topic: [BUG] select setValue does not accept numbers

gianlucagiacometti pro premium priority asked 2 years ago

Expected behavior

Let us suppose to have a button with the attribute data-myvalue="23456" and a select which contains an option with that value.

If we use jquery to get the data value, this should work:

mySelect.setValue($('#mybutton').data('myvalue'))

Actual behavior

Actually, the value is not set properly because it is not a string. The select resets to the first value.

Workaround:

mySelect.setValue(String($('#mybutton').data('myvalue')))

In my opinion, this additional check should be done directly by the funcion setValue, not by the user. Sometimes we do not know if the value is a string or a number a priori.

You just need to add String() in the setValue function

If we use vanilla js the getAttribute('data-myvalue') function gives always a string and there seems to be no issue

I prepared a snippet:

https://mdbootstrap.com/snippets/standard/gianlucagiacometti/4458108


kpienkowska staff answered 2 years ago

You probably did not "Publish" your snippet since I cannot access it.

But thanks for voicing your opinion we will take this into consideration.


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 5.0.0
  • Device: All
  • Browser: All
  • OS: All
  • Provided sample code: No
  • Provided link: Yes