html-select

Include blank for first item in select list in options_for_select tag

断了今生、忘了曾经 提交于 2019-11-27 13:24:44
问题 I tried :include_blank => true , but it didn't work. <select> <%= options_for_select Model.all.collect{|mt| [mt.name, mt.id]} %> </select> If I need to add it to the collection, how would you do that? 回答1: I think you want this format: select("model_name", "model_id", Model.all.collect {|mt| [ mt.name, mt.id ] }, {:include_blank => 'name of your blank prompt'}) BTW: was assuming Modle was suppose to be Model. To use using collection_select: collection_select(:model, :model_id, Model.all, :id,

How to expand 'select' option width after the user wants to select an option

人盡茶涼 提交于 2019-11-27 13:09:10
Maybe this is an easy question, maybe not. I have a select box where I hardcode with width. Say 120px. <select style="width: 120px"> <option>REALLY LONG TEXT, REALLY LONG TEXT, REALLY LONG TEXT</option> <option>ABC</option> </select> I want to be able to show the second option so that the user can see the full length of the text. Like everything else. This works fine in Firefox, but doesn't work with Internet Explorer6. Tomalak If you have the option pre-existing in a fixed-with <select> , and you don't want to change the width programmatically, you could be out of luck unless you get a little

HTML SELECT - Change selected option by VALUE using JavaScript

拥有回忆 提交于 2019-11-27 12:00:00
There can be many options in a SELECT dropdown. <select id="sel"> <option value="car">1</option> <option value="bike">2</option> <option value="cycle">3</option> ... </select> I'm creating a Update Profile page where a user's profile is retrieved from the database and a form is shown with those values. When it comes to SELECT dropdown, there are many options. So, its tedious test all values if (value == '1') echo "<option selected value='car'>1</option>";` So, I want to have the corresponding option selected from its value. Like when I do something like sel.value = 'bike' using JavaScript the

Pseudo elements and SELECT tag

不想你离开。 提交于 2019-11-27 11:28:47
问题 Does the select tag allows to use the :after selector in order to create a pseudo element after it? I've tried on Chrome, Safari and Firefox on Mac and it doesn't seem to work. 回答1: Here is a compromise that I have used. http://jsfiddle.net/pht9d295/3/ <div class="select-wrapper"> <select> <option>United Kingdom</option> <option>Canada</option> <option>United States</option> </select> </div> And CSS body { background-color: #f6f6f6; padding: 10px; } .select-wrapper { background-color: #FFF;

Using $index with the AngularJS 'ng-options' directive?

不问归期 提交于 2019-11-27 11:17:48
Say that I bind an array to a select tag using the following: <select ng-model="selData" ng-options="$index as d.name for d in data"> In this case, the associated option tags are assigned a sequence of index values: (0, 1, 2, ...). However, when I select something from the drop-down, the value of selData is getting bound to undefined . Should the binding actually work? On the other hand, say that I instead do the following: <select ng-model="selData" ng-options="d as d.name for d in data"> Here, the option tags get the same index, but the entire object is bound on change. Is it working this

How to get equal width of input and select fields

自古美人都是妖i 提交于 2019-11-27 10:11:13
On the form, I have one select and two input fields. These elements are vertically aligned. Unfortunately, I can't get equal width of these elements. Here's my code: <select name="name1" style="width:198px"> <option>value1</option> <option>value2</option> </select><br/> <input type="text" name="id1" style="width:193px"><br/> <input type="text" name="id2" style="width:193px"> For above example, the best width for select element is 198 or 199 px (of course I tried 193px, but the difference is major). I think, it depends on resolution, on various computers and browsers since these elements don't

Make some options in a select menu “unselectable”

筅森魡賤 提交于 2019-11-27 09:49:59
问题 I have a select element with a few options, but I want some of the options to not be selectable. Basically it's like this: <select> <option> CITY 1 </option> <option> City 1 branch A </option> <option> City 1 branch B </option> <option> City 1 branch C </option> <option> CITY 2 </option> <option> City 2 branch A </option> <option> City 2 branch B </option> ... </select> So as you can see, I don't want the cities do be directly selectable, but only the options that come under each city. How

Image in SELECT element [duplicate]

两盒软妹~` 提交于 2019-11-27 09:12:46
This question already has an answer here: How to add images in select list? 12 answers I know how to have pictures show up next to the options in a HTML dropdown form element using the CSS background-image property. However, the images do not show up on the selected element. Is there any way to do this (preferably using only CSS)? EDIT: Here is an example of the working code for the list elements. However, when the drop-down is closed, you only see the text of the selected element, without the image: <select name="form[location]"> <option value="ad" style="background: url(img/flags/ad.gif) no

Can you have multiple lines in an <option> element?

前提是你 提交于 2019-11-27 08:56:03
Is there a way to have multiple lines in an <option> element? Like this: ------------------------- | Normal <option> element | ------------------------- | <option> element broken | | onto two lines | ------------------------- | Normal <option> element | ------------------------- Is there any HTML/CSS approach, or should I use JavaScript? Álvaro González It's a particular case of displaying HTML tags inside an <option></option> element. As far as I know, browsers behave very differently in this area (Firefox displays even images, other browsers ignore most or all tags) and there isn't a cross

How do I put a space character before option text in a HTML select element?

三世轮回 提交于 2019-11-27 08:51:09
In a drop down list, I need to add spaces in front of the options in the list. I am trying <select> <option> Sample</option> </select> for adding two spaces but it displays no spaces. How can I add spaces before option texts? Rob Cooper Isn't &#160 the entity for space? <select> <option> option 1</option> <option> option 2</option> </select> Works for me... EDIT: Just checked this out, there may be compatibility issues with this in older browsers, but all seems to work fine for me here. Just thought I should let you know as you may want to replace with   I think you want   or   So a fixed