Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Materialize CSS Select Element not enabling #171

Closed
cmcknight opened this issue Aug 26, 2021 · 7 comments · Fixed by #218
Closed

Materialize CSS Select Element not enabling #171

cmcknight opened this issue Aug 26, 2021 · 7 comments · Fixed by #218
Assignees
Labels
bug Something isn't working component: select enhancement New feature or request javascript

Comments

@cmcknight
Copy link

I have two Select elements. The second Select is initially disabled until the value of the first element is changed to something other than 'all'. The behavior works as expected in vanilla HTML/JS with no MaterializeCSS. When using MaterailizeCSS, the disabled attribute is removed from the second Select but the control fails to become enabled.

Expected Behavior

My expectation is that when I remove the disabled attribute and/or set the disabled property to false on the second Select, it should become active.

Current Behavior

The second Select never becomes enabled when the value of the first select is changed from 'all' to something else.

Steps to Reproduce (for bugs)

  1. Click first Select
  2. Change value

Context

I am seeking to control the state of the second select based on the value in the first select.

Your Environment

Mac OS 11.5.2
RAM 32GB
Visual Studio Code
Materialize 1.1.0-alpha
Chrome v92.0.4515.159

Code Pen Link: link

@Smankusors Smankusors added bug Something isn't working component: select enhancement New feature or request javascript labels Aug 29, 2021
@warrenrodrigues
Copy link

I have had this issue previously. I'm not sure if it's a bug or the way it's meant to behave. Because the disabled attribute is changed outside MaterializeCSS, you have to re-initialize it, using:

var options = {};
var selects = document.querySelectorAll('select');
M.FormSelect.init(selects, options);

Forked and updated your Codepen here.

@Smankusors
Copy link
Member

IMO, this could be fixed by adding the new methods, which are .enable() and .disable() to the Select component.

You can use an alternative like @warrenrodrigues suggested.

anyway, a PR would be welcome to fix this.

@ivanBell199
Copy link

I always thought re-initialization is intended in such situations. The docs say:
You must initialize the select element as shown below. In addition, you will need a separate call for any dynamically generated select elements your page generates.

@cmcknight
Copy link
Author

I always thought re-initialization is intended in such situations. The docs say:
You must initialize the select element as shown below. In addition, you will need a separate call for any dynamically generated select elements your page generates.

The verbiage is a bit ambiguous, to be honest. One reading of it could be that if you are dynamically generating the select, as opposed to just modifying an attribute, then an additional call is needed, and I suspect that is how many read it. More clear might be "you will need a separate call to init() for any dynamically generated select or any changes to an existing select".

Just my tuppence...

@ivanBell199
Copy link

More clear might be "you will need a separate call to init() for any dynamically generated select or any changes to an existing select".

Yes, that sounds better

@wuda-io
Copy link
Member

wuda-io commented Oct 11, 2021

So what is the Solution here?
Best regards

@LoganTann
Copy link

LoganTann commented Oct 11, 2021

So what is the Solution here? Best regards

Just by editing this sentence #171 (comment) in the docs, since it seems this issue is a documented behavior, but not well explained ?

(just storing here the screenshot)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working component: select enhancement New feature or request javascript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants