question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Select option with value/title

See original GitHub issue

First of all, thanks for your awesome library, it helps me a lot…

I wonder if the library can render the select tag like:

<select>
  <option value="id1">Title 1</option>
  <option value="id2">Title 2</option>
</select>

for the enum, and I read the post https://github.com/brutusin/json-forms/issues/42, I found that we can use the script to decorate the returned object. But my situation is I load the scheme on the fly, and have no way to put the right decoration script.

I look into your source code: line 193-195:

var option = document.createElement("option");
var textNode = document.createTextNode(s.enum[i]);
option.value = s.enum[i];

then the value and the title are the same. Is there any support for value/title select in near future?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
minhdqttcommented, May 16, 2017

Thanks for your support. I put my code here to hope that it’s helpful for someone:

brutusin["json-forms"].addDecorator(function (element, schema) {
    if (element.tagName) {
        var tagName = element.tagName.toLowerCase();
        if (tagName === "select" && schema.display) {
            var opts = $(element)[0].options;
            $.each(opts, function (index, option) {
                if (index > 0) $(option).text(schema.display[index - 1]);
            });
        }
    }
});
0reactions
sunilb0575commented, Feb 25, 2019

For a drop down

'program': {
                'type': 'string',
                 'enum': programs.map((program) => program.name)
              },

where Programs is an array

programs: [ 
{id: 1, name: "Therapeutic Behavioral Services", identifier: "TBS", start_date: null, end_date: null}
{id: 2, name: "School-Based Therapy", identifier: "", start_date: null, end_date: null}
{id: 3, name: "Intensive Home Based Services", identifier: "IHBS", start_date: null, end_date: null}
{id: 4, name: "Therapeutic Foster Care", identifier: "TFC", start_date: null, end_date: null}
]

So the list of items in the drop down are names of the programs.

Is there a way I can store ID instead of name, when the user selects the name from the dropdown? @idelvall

Read more comments on GitHub >

github_iconTop Results From Across the Web

Make an unselectable option in html select - Stack Overflow
is there a way to create a select element, but in the middle of the option itens, an option that cant be selected?...
Read more >
Can i give a title to the select tag? - HTML & CSS - SitePoint
my question is, can i give some kind of title to the select tag so it will appear ... <select> <option value="0"> Select...
Read more >
How to Get the Value of Selected Option in a Select Box Using ...
Answer: Use the jQuery :selected Selector. You can use the jQuery :selected selector in combination with the val() method to find the selected...
Read more >
JavaScript Select Option - javatpoint
<title>JavaScript Selected Value</title>; <link href="css/selectbox.css" ...
Read more >
jQuery <select> get the value of selected option in a select box
Copy <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>jQuery Get Selected Option Value</title> <script ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found