2

Basically I have a text box with a modifier dropdown. I would like an icon of the current choice to display when chosen. The problem with the current set-up (using UNICODE) is that the icons do not always display, such as on google chrome (unless the specific fonts have been installed).

For example see the Fiddle: https://jsfiddle.net/q5eLLu2h/

<select class="squareDropdown" id="da" name="da">
  <option value="AND">➕&nbsp; AND</option>
  <option value="EXCEPT">➖&nbsp; EXCEPT</option>
  <option value="OR"><b>O</b>&nbsp; OR</option></select>
<input class="textArea" id="d" name="d" placeholder="d" type="text" />
<br>
<br>
<br>
<select class="squareDropdown" id="ca" name="ca">
<option value="OR"><b>O</b>&nbsp; OR</option>
<option value="AND">➕&nbsp; AND</option>
<option value="EXCEPT">➖&nbsp; EXCEPT</option>
</select>
<input class="textArea" id="c" name="c" placeholder="c" type="text" />  

Does anyone have any advice on what I could do? Either a way to get the unicode icons to display (like through forcing the person to download them?) or a simple way to get pictures or images into a select box, or anything really. Jquery UI is installed, is there anything I can do with it?

Thank you

Toni Leigh
  • 4,357
  • 3
  • 18
  • 34
WhyEnBe
  • 285
  • 6
  • 21
  • 1
    Have you considered something like [FontAwesome](http://fortawesome.github.io/Font-Awesome/)? – Ted Jun 09 '15 at 19:37
  • Could that be added straight into a selectbox option? – WhyEnBe Jun 09 '15 at 19:37
  • Ahh maybe not. You'd have to do some CSS wrangling. Let me see if I can work up a demo – Ted Jun 09 '15 at 19:39
  • Maybe use something like the Select2 plugin? – Barmar Jun 09 '15 at 19:39
  • Yeah, you'll need a replacement for the standard select, like the Select 2 mentioned above. – Ted Jun 09 '15 at 19:42
  • You can use modern CSS features to include a font on a website without forcing the user to install it. Just make sure this font is free to share. Google Fonts has a bunch of them. – Domino Jun 09 '15 at 19:52
  • are you aware, for small option sets, radio buttons may be better for usability reasons? http://ux.stackexchange.com/questions/43000/when-to-use-a-group-of-radio-buttons-and-when-to-use-a-select-drop-down – Toni Leigh Jun 09 '15 at 20:01
  • @WhyEnBe read my notes on this answer: http://stackoverflow.com/a/27053825/383904 about inconsistencies >> *Firefox has an internal glyph set which'll fallback to, while Chrome shows an empty box for the missing ones. Make sure you got the same result across devices and browsers* – Roko C. Buljan Jun 09 '15 at 21:18

1 Answers1

3

Options are hard to style.

The basic reason is that they are reaching into the operating system for generation rather than being generated solely by the browser like most other website HTML elements.

This is why file upload form field 'submit' buttons don't follow the same rules as any other submit buttons on a form.

Here is some more detail about limited and inconsistent possibilities and a question that proves <option> can't have any children (this in turn stops the psuedo-elements from working, unfortunately, as psuedo elements are rendered like DOM nodes).

All this means that using an icon font won't work either as you'd need to target just the bit with icon in, which you could only do with extra child elements.

Using JQuery

There are many ways of mimicking select option form fields with various javascript plugins that will give you more control, however, they come with an important caveat. Standard select elements bring with them all the extra usability and accessibility features (such as keyboard focus and operation) javascript plugin writers don't necessarily think about, so use with care.

It's also worth remembering that when you are replacing complex functionality with JQuery you've got quite a lot of overhead in testing / development - select elements do just work in all browsers, without their actual functionality needing testing. This is more considerable if you do pay attention to all the accessibility points.

The MDN article does however judge that this is the best way and lists some good plugins for a solution, which I would use as MDN can be trusted to have considered all the important stuff I mention above.

For the sake of link rot, here are the two of the three they recommend that link to a product still:

UniForm

FormalizeMe

(please note, I haven't tried these, I'm just trusting Mozilla!)

Unicode

You are trying to use unicode in your option tags. This should work, and without forcing a download on the user if you:

  • Use a font that has the unicode characters you want to use defined.
  • Ensure that you have the charset in your docs set to utf-8

However, you'll only ever get characters, never styleable icons and you might be stuck with websafe or proprietary fonts.

This jsfiddle here demonstrates with the web-safe font-family: sans-serif and also characters taken from this link with a big list of those that are commonly supported

And finally

For small option sets radio buttons are probably better. The user can immediately see the available options rather than having to open them each time (better learnability, faster cognition); plus, they can make their desired selection, or change their desired selection with just one click each time. The guys over at UX.SE discuss what to use further, raising other points.

All your problems might just disappear if you think about whether <select> is the best option.

Community
  • 1
  • 1
Toni Leigh
  • 4,357
  • 3
  • 18
  • 34
  • Thanks for your answer. The problem I am having with Unicode is that the specific characters (heavy plus and heavy minus) do not display in google chrome unless the fonts have been installed on the computer. – WhyEnBe Jun 09 '15 at 21:15
  • personally I'd rank the given options like this: reconsider using a select > use a good, researched JQuery plugin (rather than the first you spot) > get a web-font that supports the obscure unicode characters in the designs – Toni Leigh Jun 09 '15 at 21:18
  • Thanks I ended up just styling my own fonts. – WhyEnBe Jun 10 '15 at 16:06
  • @WhyEnBe - sounds interesting, how do you mean? – Toni Leigh Jun 10 '15 at 16:23
  • Well I just needed the plus and minus characters to look larger; more like the "heavy plus" and "heavy minus" so I took an open font file deleted all of the other characters and modifed the two characters I needed to be larger and other minor line adjustments. Next I added this font to the font file for this class, so it is the first font getting called, but only for those two symbols. – WhyEnBe Jun 10 '15 at 16:36
  • @WhyEnBe I'm guessing you got over the font inclusion errors, I must admit I didn't think of editing a font as a viable answer, maybe on design.SE! – Toni Leigh Jun 10 '15 at 16:41
  • well I had never tried anything like it before but it was really straightfoward and quick. – WhyEnBe Jun 10 '15 at 16:50