Different multiple select rendering for each browser

Asked

Viewed 533 times

6

I have the following code:

<select multiple="multiple" id="carros" size="1" name="carros">
    <option value="volvo">Volvo</option>
    <option value="saab">Saab</option>
    <option value="opel">Opel</option>
    <option value="audi">Audi</option>
</select>

In the 10, select render with size equal to one and the navigation arrows as expected, the 27.0.1 renderiza with size one, but without the navigation arrows and the 32.0.1700.102 m never respects the size less than four and only after the fourth element enables the navigation arrows.

I know with height I would achieve the expected behavior. Is there any way to get and respect the same behaviour as 10, with the size really equal to one and with navigation arrows only using HTML?

Follows a fiddle example that should be opened in each browser to view the problem.

  • There really is a need to use select multiple="multiple"?

  • @Tiagocesaroliveira select multiple="multiple" is the only way I know to select more than one element, right?

1 answer

3


In Chrome it is not possible to resolve only with HTML due to a bug unresolved when the attribute size is less than 4.

And Firefox also has a open bug scheduled for future resolution, i.e., they give no priority to this.

I believe that the reason these bugs have never been fixed is that it makes no sense to have a multiple selection element that displays only one element at a time.

When talking about a browser "respecting the behavior" of another, this is a delicate subject, after all each browser has its own characteristics. Probably, IE only works because it uses native Windows components, while other browsers use components of their own. And I think almost no one would want those browsers to go to imitate the IE.


Update: alternatives

Thinking about how to solve the issue of not using more screen space and at the same time provide a good user experience across all browsers, the solution I found to be more feasible and straightforward to implement would be the use of a component wrapper at the select HTML. One of them is the jQuery UI Multiselect, although not sure about compatibility in older versions of Internet Explorer.

Another option would be to create a simplified version of the arrows to scroll up and down with Javascript to scroll the select content. Honestly, I don’t know if this solution would behave well in all browsers. I did a very simple test in this fiddle. It is necessary to invest time to test it.

Follow the main code:

$('#up').click(function() {
    $('select').scrollTop($('select').scrollTop() - 10);
});
$('#down').click(function() {
    $('select').scrollTop($('select').scrollTop() + 20);
});

And one last alternative I considered was to resize the field when it gets the focus so that the user can select the items. See the code example:

$('select')
.focus(function() {
    $(this).animate({height: "60px"}, 500);
})
.blur(function() {
    $(this).animate({height: "20px"}, 500);
});

Fiddle

  • 2

    I agree that it makes no sense for a multiple selection select to have only one element being displayed at a time. In fact, there are more elegant ways to resolve such issues. Personally, I’ve never used multiple selects, but I’m not setting myself up here as a role model for anyone. Just note that it is unusual use, hence the unwillingness to treat such "Feature".

  • @utluiz I think this is the first and, perhaps, only case where others should imitate the IE, after all the rule is clear, has to appear navigation arrows if the number of elements is greater than the attribute size and the number of lines to appear is defined by such an attribute.

  • @Tiagocesaroliveira I am a back-end developer and do not handle HTML and CSS. I get them defined and implement, because of layout the client defined the HTML so because the browser approved for intranet systems is the IE 8, but as I develop using Chrome and FF I realized the difference between the two, I went to look at the IE and noticed the third behavior. The client is satisfied, I wanted a more elegant solution for FF and Chrome users, because although not-approved are not prohibited, but work even has to be IE 8 up.

  • @Philippegioseffi got it! Good to see that you care about other browsers!

  • @Tiagocesaroliveira anyway thank you, I will use CSS to define an equal behavior in the three. So I get right?

  • @Philippegioseffi believe that yes, sincerely never worked with select Multiple...

  • Thank you then, @Tiagocesaroliveira.

  • Maybe @utluiz can help me with this.

  • @Philippegioseffi Tomorrow morning I do some tests!

  • @Philippegioseffi I updated the answer with some alternatives. Unfortunately there is nothing magical that makes the component work, but I left there 3 possible solutions.

  • @utluiz Three excellent solutions, I will go with the first, multiselect if I can edit the "visual" component to match the visual identity of the client and the system, otherwise I will leave as it is, because as I said the client is satisfied.

Show 6 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.