Dogfalo / materialize

Materialize, a CSS Framework based on Material Design

Home Page:https://materializecss.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Value change of select does not affect visuals

opened this issue · comments

Problem

Changing selected value of a <select> with Javascript does not change the visual selection.

I am using Javascript to change a selected value of a <select>, getting the select element by id and setting it's value to a different option value.
This works just fine, but the visual selection in the select input-field does not change. Clicking afterwards on it, shows the new selected value and will then display it correctly in the input-field.

Is it possible to change the visual selection, if the selected value changes programmatically? For my usecase, I need to show the change of the selection immediately.

Reconstruction:

CodePen

Simply call the formSelect() method again after setting the value programmatically. That should do the trick.

Thanks! This did the trick. I just found out that the "onchange" event does not fire and this seems to be the problem of javascript.