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.

Dynamic Dropdown with remote content

See original GitHub issue

Hi, I wrote my code like that

      $('.dropdown#brands')
        .dropdown({
          apiSettings: {
            url: 'https://sneakerfans.herokuapp.com/api/v1/allbrands',
          },
          fields: {
            remoteValues: 'brands',
            name: 'brand_name',
            value: 'id'
          },
          allowReselection: 'ture',
          placeholder: 'select brands',
          direction: 'downward',
          onChange: (value, text, $choice) => {
            regvue.brand_id = value
            if (!regvue.tech) {
              regvue.tech = true
            }
            $('#techs')
              .dropdown({
                placeholder: 'select techs',
                fields: {
                  remoteValues: 'techs',
                  name: "tech_name",
                  value: "id"
                },
                apiSettings: {
                  url: 'https://sneakerfans.herokuapp.com/api/v1/gettechs',
                  method: 'post',
                  beforeSend: (settings) => {
                    console.log(regvue.brand_id)
                    $('#techs').dropdown('refresh')
                    settings.data = {
                      brand_id: regvue.brand_id,
                    }
                    return settings
                  }
                }
              });
          }
        });

There should be two dropdowns, first use api to get content from server, and when first dropdown change its value, the second dropdown use api and the value from first dropdown to get a different options.

However, the second dropdown content doesn’t change when I change first dropdown value.

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
kmd1970commented, Feb 24, 2017

As of 2.2.9 you should be able to do this like below. No sessionStorage.removeItem should be needed. Also, I use class selectors instead of ids, looks cleaner.

Now, once you click inside the techs field it should display the correct filtered options based on the brands selection.


$('.ui.dropdown.techs').dropdown({
                filterRemoteData : true,
                placeholder: 'select techs',
                fields: {
                  remoteValues: 'techs',
                  name: "tech_name",
                  value: "id"
                },
             apiSettings: {
                  url: 'https://sneakerfans.herokuapp.com/api/v1/gettechs?brand_id={brand_id}',
                  method: 'get',
                  beforeSend: (settings) {
                   // get the brands selected value
                    var brand_id = $('.ui.dropdown.brands').dropdown('get value');
                    settings.urlData.brand_id = brand_id: 
                    return settings
                  }
            }
 });

$('.ui.dropdown.brands').dropdown({
          apiSettings: {
            url: 'https://sneakerfans.herokuapp.com/api/v1/allbrands',
          },
          fields: {
            remoteValues: 'brands',
            name: 'brand_name',
            value: 'id'
          },
          allowReselection: 'true',
          placeholder: 'select brands',
          direction: 'downward',
          onChange: (value, text, $choice)  {
            // clear the techs dropdown
            $('.ui.dropdown.techs').dropdown('clear');
           //2.2.9 currently has a bug where the search value doesn't clear.
           $('.ui.dropdown.techs').find('.search').val('');
          }
});
0reactions
rlopezbcommented, Nov 15, 2018

Use: $('#drop').dropdown('change values',null); The next click will in #drop will trigger the query…

Read more comments on GitHub >

github_iconTop Results From Across the Web

So You Need To Fill a Dropdown Dynamically
The first one has three options. The first just informs the user to select an option, and the next two are actual choices....
Read more >
Create a Dynamic Dropdown List - Google Sheets - YouTube
Want to learn how to create a dynamic drop down list in Google Sheets? It happens when you click a small drop down...
Read more >
change content dynamically based on dropdown select
You code works fine, just you need to add eventListener , which calls changes every-time when you change dropdown value of select, as...
Read more >
Dynamic dropdown list from a linked sheet
Hi, wondering if it's possible to have a dropdown list in ... But is it possible to use a custom (remote) source for...
Read more >
Dynamic Dropdown - Resource Center
A new content dropdown field type is now available in the widget builder. Now you can dynamically populate a dropdown field in a...
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