Add an attribute to an option of a select input

Add an attribute to an option of a select input

chrisg123chrisg123 Posts: 9Questions: 4Answers: 0
edited October 2015 in Editor

I am looking add a title attribute to options of a select input

I tried this already:

type: 'select',
                options: [
{ label: "Tri-annually", title:'Every 4 months', value: "quarterly" } ...

but the title attribute doesn't work like this.

I have also tried

{label: "Once", attr: {title:'One time only'},value: "once"} ...

but this also doesn't seem to work.

How might I go about doing this?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Answer ✓

    Hi,

    Just to confirm, you want to set the title attribute for the option elements rather than the select itself? That unfortunately is not something that Editor currently offers.

    There are two or three ways this could be done:

    1. Create a new plug-in input type that adds this ability
    2. Modify the built in option
    3. Update the options that Editor has created (usee-api field().input()to get the-tag select` element).

    Is this to show a browser tooltip with the extended text?

    Allan

  • ThomDThomD Posts: 334Questions: 11Answers: 43

    The select HTML element doesn't support a title for input items. Label and value are the native attributes.

    Where do you think this attribute would appear?

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin

    The select HTML element doesn't support a title for input items

    Do you mean the option elements? I've just tried it in Chrome before posting back and it did show up.

    The HTML 5.1 spec says that the option element supports the global attributes, which includes the title attribute.

    Allan

  • ThomDThomD Posts: 334Questions: 11Answers: 43

    I stand corrected. I've never seen it referenced outside the spec documents. (Who reads those?)

    Back to the OP, use jquery's .attr() function.

  • chrisg123chrisg123 Posts: 9Questions: 4Answers: 0
    edited October 2015

    Hey Allan,

    Yes the idea was to show a tooltip on the option tag. I guess I will look into creating a plugin input type as you suggest.

    ThomD thanks for your input. I know i could just modify it with jquery but i was hoping to keep all the configuration for Editor in one place and not use jquery independently.

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin

    If it were something I could see being used relatively frequently I wouldn't hesitate to put this into the core, as its just a line of code I think, but I'm trying to be really strict about additional features at the moment to keep bloat down.

    If anyone else posts about this I'll look into adding it in.

    Allan

This discussion has been closed.