question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Dropdown appears in sweetalert 2 when initializing materialize dropdowns

See original GitHub issue

Current behavior

A drop down menu appears in sweet alert 2 alerts when materialize is used and drop downs initialized. This occurs even if no input is specified for the alert.

image

Expected behavior

No dropdown to appear if it is not required as an input image

Live demo

https://jsbin.com/peqatexaze/edit?html,js,output

You will notice the dropdown appear. Remove:

$(document).ready(function(){
    $('select').formSelect();
});

and the dropdown will no longer appear.

An issue has been opened with the creator here but he is unfamiliar with materialize so I thought an issue here may help solve this.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:10

github_iconTop GitHub Comments

2reactions
leomotycommented, Nov 9, 2018

The way Materialize works is, a <select> is replaced with a custom component (the select is actually still there but hidden) containing a <input> plus a dropdown. As seen here: https://github.com/Dogfalo/materialize/blob/v1-dev/js/select.js#L216

What you could do instead is restrict which <select>s gets the materialize treatment (adding a specific class, for example).

If you just wanna ignore this specific case, this should work:

$('select:not(.swal2-select)').formSelect();

Which will match any select but the one created by swal({...}).

Edit:

Updated your demo:

https://jsbin.com/pakiqad/1/edit?html,css,js,output

0reactions
erdrborgescommented, Sep 19, 2019

The way Materialize works is, a <select> is replaced with a custom component (the select is actually still there but hidden) containing a <input> plus a dropdown. As seen here: https://github.com/Dogfalo/materialize/blob/v1-dev/js/select.js#L216

What you could do instead is restrict which <select>s gets the materialize treatment (adding a specific class, for example).

If you just wanna ignore this specific case, this should work:

$('select:not(.swal2-select)').formSelect();

Which will match any select but the one created by swal({...}).

Edit:

Updated your demo:

https://jsbin.com/pakiqad/1/edit?html,css,js,output

I had the same problem described by @cheesemarathon, and this workaround works fine. Thanks for your explanation.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dropdown - Materialize
The DOM element the plugin was initialized with. options, Object, The options the instance was initialized with. id, String, ID of the dropdown...
Read more >
missing select options with Sweet Alert - Stack Overflow
Your code works just fine with included SweetAlert2 library: Swal.fire({ title: 'Select Outage Tier', input: 'select', inputOptions: { '1': ...
Read more >
Common problems - The jQuery replacement for select boxes
This issue occurs because Bootstrap modals tend to steal focus from other elements outside of the modal. Since by default, Select2 attaches the...
Read more >
Dogfalo/materialize - Gitter
Hey guys, I would like to report a bug while using the custom "<select>" element with ... init.js:22 j @ jquery-3.1.0.min.js:2 k @...
Read more >
Form Select2 - Material Design Admin Template - Pixinvent
Materialize is a Material Design Admin Template,It's modern, ... Select2 gives you a customizable select box with support for searching, tagging, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found