Add an attribute to an option of a select input
Add an attribute to an option of a select input
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
This discussion has been closed.
Answers
Hi,
Just to confirm, you want to set the title attribute for the
option
elements rather than theselect
itself? That unfortunately is not something that Editor currently offers.There are two or three ways this could be done:
use
e-api field().input()to get the
-tag select` element).Is this to show a browser tooltip with the extended text?
Allan
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?
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
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.
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.
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