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.

Ability to initialise option items selected

See original GitHub issue

I wanted to reflect settings in the DB when the page was loaded but could not find a way to add an option as selected. I have modified my local file thus:

    'addOption' : function(options){
      var that = this;

      if (options.value !== undefined && options.value !== null){
        options = [options];
      } 
      $.each(options, function(index, option){
        if (option.value !== undefined && option.value !== null &&
            that.$element.find("option[value='"+option.value+"']").length === 0){
          var $option = $('<option value="'+option.value+'">'+option.text+'</option>'),
              index = parseInt((typeof option.index === 'undefined' ? that.$element.children().length : option.index)),
              $container = option.nested === undefined ? that.$element : $("optgroup[label='"+option.nested+"']");

          // PB: 23-06-2016:  If marked as selected from start, reset template
          if (option.selected != undefined)
              $option = $('<option value="' + option.value + '" selected>' + option.text + '</option>')

          $option.insertAt(index, $container);
          that.generateLisFromOption($option.get(0), index, option.nested);
        }
      });
    },

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
peterbrennencommented, Oct 18, 2016

I’ll search my code tomorrow to find how I call it.

0reactions
peterbrennencommented, Oct 28, 2016

My pleasure 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Correct way to initialize with an option already selected? #143
I'm trying to initialize a ui-select input field with a previously saved option. What's the right way to go about selecting the option...
Read more >
initialising option in <select></select> in angular 6
Show activity on this post. I want to run code (initialize)="selectedQueryType=queryTypes[0]" when the component mounts, so that default value ...
Read more >
Solved: Combo Box Reset - Power Platform Community
I have an issue here: - I try Button. Pressed to Reset the selected items to "Fnd items" (that is before any item...
Read more >
Select - Materialize
Select allows user input through specified options. Make sure you wrap it in a .input-field for proper alignment with other text fields.
Read more >
Initialization Options - Items API - Learnosity Reference
Provide custom initialization options to the Annotations API. This can be used to enable or disable specific modules, or customize their behavior.
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