Hi. In latest rc2 and now on 1.0.0 version, form selects have a bug on the getSelectedValues method. The result of the method is the previous selected value on select box, and not the current one.
Example here:
https://codepen.io/anon/pen/EepMZL
Same behaviour. It's looks like that function below _setSelectedStates() should be executed in _handleSelectChange(e) instead of _handleInputClick() and it is working fine.
https://github.com/Dogfalo/materialize/blob/80e8ed370487aaf1e2185b028f7deda40da94eb9/js/select.js#L155
https://github.com/Dogfalo/materialize/blob/80e8ed370487aaf1e2185b028f7deda40da94eb9/js/select.js#L106
Also have this issue. I got around it for now by using instance.el.selectedIndex to get the index of the selected value.
Same behaviour. It's looks like that function below
_setSelectedStates()should be executed in_handleSelectChange(e)instead of_handleInputClick()and it is working fine.
materialize/js/select.jsLine 155 in 80e8ed3
this._setSelectedStates();
Line 106 in 80e8ed3
_handleSelectChange(e) {
Hmm, this will not work correctly.
When the change trigger fires for the original select element,
getSelectedValues should return the correct values.
Removing the _setSelectedStates call from _handleInputClick and adding it to _handleOptionClick just before the change trigger call, seems to work for any case
Same behaviour. It's looks like that function below
_setSelectedStates()should be executed in_handleSelectChange(e)instead of_handleInputClick()and it is working fine.
materialize/js/select.js
Line 155 in 80e8ed3
this._setSelectedStates();
materialize/js/select.js
Line 106 in 80e8ed3
_handleSelectChange(e) {Hmm, this will not work correctly.
When the change trigger fires for the original select element,
getSelectedValues should return the correct values.
If we call _setSelectedStates() after _setValueToInput() in _handleSelectChange(e), seems to work too. Anyway it's a bug in this component.
Yes it works too that way, but maintaining the selection should be an internal task and imo it should be done asap when the change occurs.
An important reason is that other components might have a listener for the change event in the original select element and when that events fires, it should report the correct selected value.
That is exactly the case in my app and then only fix is to call _setSelectedStates() before the change event
Fixed in 4a68ebd1
.getSelectedValues() returns previous selection again
check here https://codepen.io/anon/pen/EepMZL
If I understand correctly a patch for this isn't released yet.
@4selin @glmars Has this been fixed yet?
@rishav394 as @acburst said "Fixed in https://github.com/Dogfalo/materialize/commit/4a68ebd12c85b81e188988760ec6f16899864da3", but as I know a new version with this fix has not been released yet :(
Having same issue
Same issue here :(
I used a combination of the below to get the values
var elems = document.querySelectorAll('select');
var instances = M.FormSelect.init(elems);
elems.forEach(function(el) {
$(el).on('change', updateAction)
})
function updateAction() {
var selection = $(this).val();
}
I know its a bit messy with both js and jquery but...
same issue here, v 1.0.0. When the fix will be released?
Targeting this weekend. We have to do some additional testing due to some
changes in our build toolchain
On Mon, Oct 28, 2019 at 9:51 AM Anna Carolina notifications@github.com
wrote:
same issue here, v 1.0.0. When the fix will be released?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/Dogfalo/materialize/issues/6123?email_source=notifications&email_token=AAVFVR2MNFWL4I2GZTOX5XTQQ4J73A5CNFSM4FVJCYKKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOECNSZWQ#issuecomment-547040474,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AAVFVR7NE6PSIAG5HEYAFXDQQ4J73ANCNFSM4FVJCYKA
.
--
Doggy sends his greetings from Mars.
same issue here, when the fix will be released?
I added
M.AutoInit();
Before consulting the value of the select and the problem was fixed, it is probably not the best idea. but it works.
Same issue here, when is the fix expected ?
same issue here....
Any more update on whether a patch for this is forthcoming? I just ran into this issue myself.
Still broken
I also have this issue. The Workaround by @Egeroth24 works fine.
Still broken.
I just wanted to chime in that I'm getting this error where the form select is lagging one behind like other people. I'm currently using `react-materialize: 3.9.3" but thankfully @Egeroth24 workaround solved the problem for me as well.
Most helpful comment
.getSelectedValues() returns previous selection again
check here https://codepen.io/anon/pen/EepMZL