Pre-select (default) value in CCDD

Forums Cascading dropdowns Pre-select (default) value in CCDD

Viewing 3 reply threads
  • Author
    Posts
    • #15182
      Artaker
      Participant

      Hi

      In the CCDD configurtation I can enter a default value that is shown when there is no value selected.
      Now in my case there should always be a value selected, depening on the first field the secoind should have a default value chosen.

      To be presice: I have a CCDD with country and city. The available selction of cities depends on the selected country. There is only one County to select and one city to choose. This works fine with the given CCDD. (Working on a lib here)
      Experice showed, that in every country there is one city with the most entries, so the users would like to have this value pre-selected. Meaning if you select the country, a given default value (city) is automatically filled in the city field (if there is nothing chosen so far).

      I tried to use a cunstom function to read out the country, and then use a switch statement to fill in the city field. I put that function with a rule that triggers on the country not empty (or changed). I also tried it with an onLoad trigger rule, where I know the country was already filled in. It doesn’t select the city with the form openend.
      BUT when I save the form, I then have the default value saved (if there wasn’t anything selected before)

      Maybe I’m thinking in the wrong direction here, not seeing the obvious
      Would you have any tip how I can accomplish that?

      Thanks
      Best regards,
      Nicole

      Version information
      Autocomplete: 1.4.6
      Cascading dropdowns: 3.527
      DFFS frontend: 4.365
      DFFS frontend CSS: 4.14 / 4.14
      jQuery: 1.12.1
      Lookup: 1.12
      Resource management: 2.42
      SPJS-Utility: 1.260
      vLookup: frontend v2.264

      • This topic was modified 7 years, 3 months ago by Artaker.
      • This topic was modified 7 years, 3 months ago by Artaker.
    • #15185
      AdamP
      Participant

      Hi Nicole

      If I understand your situation correctly, Alexander has already thought of this and included it as standard;
      -In DFFS config there is a check box for “Autofill subsequent dropdowns when they contain only one valid option”
      -Standalone there is a parameter to set – “autoselectSingleOption:true If the next dropdown contains only one option it will be automatically selected.”

      Have you tried either of these?

      See guide

      Adam

      • #15188
        Artaker
        Participant

        Hi Adam

        Yes I do use this, but this only helps if the 2nd dropdown has only ONE value – which for me is only the case for one country. For all other countries there is more than one city available in the dropdown.

        So while it’s really handy to have the value pre-selcted if there is only one, here I would need to be able to pre-define the value that is going to be pre-selected, even if there are more values to choose from. (Since it’s a default and not a fixed value)

        Thanks
        Best regards,
        Nicole

    • #15273
      Alexander Bautz
      Keymaster

      Hi,
      I don’t think I can add this as a built in functionality so you would need some custom code. If you could provide a “mapping” for each selected option, and the value to preselect I might be able to create a code snippet.

      Alexander

      • #15490
        Artaker
        Participant

        Hi,
        sorry for the dealy.

        It’s like this
        ———-
        Country – City
        Bulgarien – Sofia
        Bosnien-Herzegowina – Sarajevo
        Kroatien – Zagreb
        Polen – Krakau
        Serbien – Belgrad
        Slowenien – Ljubljana
        Tschechien – Prag
        Ungarn – Budapest
        Österreich – Wien
        Slowakei – Bratislava
        Deutschland – Berlin
        ———-

        Thanks for any tips

        BR
        Nicole

    • #15573
      Alexander Bautz
      Keymaster

      Hi,
      Add this code to your Custom JS:

      // Maps default city
      var mapDefaultCity = {
          "Bulgarien":"Sofia",
          "Bosnien-Herzegowina":"Sarajevo",
          "Kroatien":"Zagreb",
          "Polen":"Krakau",
          "Serbien":"Belgrad",
          "Slowenien":"Ljubljana"
      };
      
      $("#dffs_COUNTRY").on("change","select",function(){
          var country = $(this).find("option:selected").text();
          if(mapDefaultCity[country] !== undefined){
              setTimeout(function(){
                  setFieldValue("CITY",mapDefaultCity[country]);
              },500);
          }
      });

      Change “COUNTRY” and “CITY” for your fields names – and fill in more countries and corresponding cities in he map-object.

      Let me know how this works out.

      Best regards,
      Alexander

Viewing 3 reply threads
  • You must be logged in to reply to this topic.