I am working on a project which uses Materialize css for front end.
Is there any way to get multi select option for dropdown in Materialize css ?
Any piece of info would be helpful.
You only have to add the multiple:
<div class="input-field col s12">
<select multiple>
<option value="" disabled selected>Choose your option</option>
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="3">Option 3</option>
</select>
<label>Materialize Multiple Select</label>
</div>
And then call js:
$(document).ready(function() {
$('select').material_select();
});
jsfiddle
MaterializeCSS's dropdown implementation is not a <select> block. It is just a styled <ul>. Therefore, I don't believe you can take advantage of a multi-select with their implementation. I would use the default <select> block like this:
<select class="browser-default" multiple>
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="3">Option 3</option>
</select>
Note: you must add the browser-default class so that MaterializeCSS doesn't render it.
Since the top and left css properties of the label are set to ~0.8rem each, you can add a specific rule to the li's:
#topics_dropdown li {
height: 3rem;
}
Related
I am using Materialize.css library (v 1.0.0), as of 2018 for my project to add the material components. However, I failed to initialize two select boxes with it.
I have two select boxes in my page.
$(function() {
$("#numPagesPaginate").formSelect();
$("#numRatingsEdit").formSelect();
});
<select id="numPagesPaginate" name="numPagesPaginate" data-ng-model="bkCtrl.page.pageSize">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
<select id="numRatingsEdit" name="numRatingsEdit" style="display:none">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
However, when I initialize both the select boxes using this only the first one works.
In addition, if I initialize the second selectbox in the script tag elsewhere, the box gets initialized and works, but there is one duplicate selectbox.
Edited: To add this question, I want to tell you that I have read the documentation and the default method. However, no results.
You should follow documentation and initialize globally with one line:
$('select').formSelect();
Just like Serg said, you should follow the documentation properly.
<div class="container">
<div class="row">
<div class="col s6">
<label>Num Pages Paginate</label>
<select id="numPagesPaginate" name="numPagesPaginate" data-ng-model="bkCtrl.page.pageSize">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
</div>
<div class="col s6">
<label>Num Ratings Edit</label>
<select id="numRatingsEdit" name="numRatingsEdit">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
</div>
</div>
</div>
<script>
$(document).ready(function () {
$('select').formSelect();
});
</script>
Anybody knows why the materialize select It’s not working if has the input-field class? I’m using the last materialize version(0.100.2). I’m also adding all the requiered files(css,js,jquery). It works if use the "browser-default" class but not with the "input-field". Any idea of why it’s not working? Help.
It should work like this, but it is not:
<div class="input-field col s12">
<select>
<option value="" disabled selected>Choose your option</option>
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="3">Option 3</option>
</select>
<label>Materialize Select</label>
</div>
Only works like this, and looks bad:
<label>Browser Select</label>
<select class="browser-default">
<option value="" disabled selected>Choose your option</option>
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="3">Option 3</option>
</select>
I am trying to style a SELECT / OPTION boxes using INLINE CSS.
The background-color does not seem to be working:
<option style='bakground-color:red'>text</option>
Basically, I want 3-4 options, but each line to have a separate colored background.
All the CSS examples I have found use external CSS files, or a separate STYLE section above the area I'm working on.
Is it possible to do this inline?
Yes, if you want to give inline style then you can give.
The style is not working in your code because you have a spelling mistake.
You write bakground-color instead of background:color
<select>
<option value="1" style="background-color:yellow">Option 1</option>
<option value="2" style="background-color:orange">Option 2</option>
<option value="3" style="background-color:red">Option 3</option>
<option value="4" style="background-color:green">Option 4</option>
</select>
<option value="aa" style="background: black;">aa</option>
<option value="bb" style="background: blue;">bb</option>
This will show when you select an option from dropdown.
Yes, you can do it inline.
<select>
<option value="green" style="background: green;">green</option>
<option value="cyan" style="background: cyan;">cyan</option>
<option value="yellow" style="background: yellow;">yellow</option>
</select>
I have a <select> and want the first option to be invisible since there is not enough space for the text on the mobile version and it gets chopped off anyway so I resolved to just make it disappear but it wont work. Only with the rest of the options (on PC browsers) but not for the first one. Why is that?
This is what I've already tried
CSS:
option:first-child {
color: transparent;
}
HTML:
<select>
<option value="">Please select</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
Thank you.
option:first-child{
display: none;
}
<select>
<option disabled value>Please select</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
using javascript (best way)
(function(){
document.getElementById("first").text = "";
})()
<select id="mySelect">
<option value id="first">Please select</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
if you want to hide first option only in mobile, then follow this
(function(){
var window_width = $(window).width();
if(window_width < 480){
document.getElementById("first").text = "";
}
})()
<select id="mySelect">
<option value id="first">Please select</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<p>This will hide only in mobile screen</p>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
You can set it to display: none; only issue is, it won't work in Internet Explorer (surprise!)
Or just leave the <option> empty...
I think you don't really need to add any css for this reason. If you need to the first option to be blank, then remove Please Select .i.e.,
<select>
<option value=""></option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
If you want some spacing will be there inside the box even though text is removed you can just add a few times to make look the panel wide enough as show below.
<select>
<option value=""> </option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
Here is a working pluncker for you. Change it to display:none and add select to the CSS
OR
You can use visibility: hidden; instead of display:none in CSS
select option:first-child {
display:none;
}
<select>
<option value="">Please select</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
jQuery.fn.toggleOption = function(show) {
jQuery(this).toggle(show);
if (show) {
if (jQuery(this).parent('span.toggleOption').length)
jQuery(this).unwrap();
} else {
if (jQuery(this).parent('span.toggleOption').length == 0)
jQuery(this).wrap('<span class="toggleOption" style="display:none;" />');
}
};
You can use media query to handle small devices and phones:
/* you can set any width you want */
#media (max-width: 400px) {
select option:first-child {
display: none;
}
}
<select>
<option style="display:none;">Please select</option>
<option value="1">one</option>
<option value="2">two</option>
<option value="3">three</option>
<option value="4">four</option>
</select>
Thanks... :)
I have a problem with IE11 and menu.
When opened the combo, the cursor changes depending on the input behind.
<div>
<select>
<option value="1">option 1</option>
<option value="2">option 2</option>
<option value="3">option 3</option>
<option value="4">option 4</option>
</select>
<input type="text" value="mouse changes" readonly="readonly" />
</div>
When trying in IE11, the cursor changes in option 2, to the readonly, it select the option if clicking but it seems forbidden option.