Dynamic Dropdown Issues

wibadd 04 Feb, 2012
I am using the Dynamic Dropdown action as the first in the On Load event. I have been given a requirement to provide state/province and country selections and default the values to Wisconsin and United States, respectively. The US country selection should provide a list of all states and a selection of Canada should provide a list of all provinces. The user should then be able to select Other as the country value and be able to input both country and state/province values.

Here are the values from the Dynamic Dropdown:

CAN:AB=Alberta, BC=British Columbia, MB=Manitoba, NB=New Brunswick, NL=Newfoundland and Labrador, NT=Northwest Territories, NS=Nova Scotia, NU=Nunavut, ON=Ontario, PE=Prince Edward Island, QC=Quebec, SK=Saskatchewan, YT=Yukon
USA:AL=Alabama, AK=Alaska, AZ=Arizona, AR=Arkansas, CA=California, CO=Colorado, CT=Connecticut, DE=Delaware, DC=District of Columbia, FL=Florida, GA=Georgia, HI=Hawaii, ID=Idaho, IL=Illinois, IN=Indiana, IA=Iowa, KS=Kansas, KY=Kentucky, LA=Louisiana, ME=Maine, MD=Maryland, MA=Massachusetts, MI=Michigan, MN=Minnesota, MS=Mississippi, MO=Missouri, MT=Montana, NE=Nebraska, NV=Nevada, NH=New Hampshire, NJ=New Jersey, NM=New Mexico, NY=New York, NC=North Carolina, ND=North Dakota, OH=Ohio, OK=Oklahoma, OR=Oregon, PA=Pennsylvania, RI=Rhode Island, SC=South Carolina, SD=South Dakota, TN=Tennessee, TX=Texas, UT=Utah, VT=Vermont, VA=Virginia, WA=Washington, WV=West Virginia, WI=Wisconsin, WY=Wyoming
Other:Other=Other

Unfortunately, they are only loading and working when the country is changed from the default of United States. Even when the values are selected, the form displays a validation when submitted. It seems like the value from the Dynamic Dropdown is not being passed to state_province. I originally though this was just an issue with setting a default value and tried adding to the JS Load after the Dynamic Dropdown load, but that didn't work and it obviously still does not solve the issue with the value being passed to state_province. I'm stuck and I need to have a working version of this form for Mon 2/6.
GreyHead 04 Feb, 2012
Hi wibadd,

I got a version working near enough OK.[list=a]
  • Remove the 'Selected' value from the Country drop-down.

  • Edit the options list to add a first 'null' option like this
    CAN: =Choose,AB=Alberta,BC=British Columbia, . . .
    USA: =Choose,AL=Alabama,AK=Alaska,AZ=Arizona, . . .
    . Note that I've also removed the spaces after the commas as these were being included in the values.
  • [/list:o]
    You should then find that the options and validation both display correctly - and you have forced the user to make a positive choice rather than accepting the defaults.

    Because of the way Max has written the code for this I don't see a quick solution to having a default country set and getting the state list loaded from it. If that is essential then we can take a look but it's not a two - or even a ten - minute fix :-(

    Bob
    wibadd 04 Feb, 2012
    Thanks for the response and note about the spaces. Unfortunately, I have been given a requirement to set defaults for country and state/province so I need to figure out some solution to it. I tried the double dropdown using JS as indicated in the cookbook and on http://greyhead.net/chronoforms/creating-a-double-drop-down but I wasn't able to get it working. Max suggested using the double dropdown, but it appears this won't be a feasible option to set a default. Do you have a recommended way of accomplishing this (i.e. - php, Ajax, etc.)?
    GreyHead 04 Feb, 2012
    Hi wibadd,

    Ading this into a Load JS action after the Dynamic DropDown action seems to do the trick:
    window.addEvent('load', function() {
      if ( $('input_select_0').value == '' || $('input_select_0').value == ' ' ) {
    	  $('input_select_0').value = 'USA';
      }
      $('input_select_0').fireEvent('change');
      if ( $('input_select_1').value == '' || $('input_select_1').value == ' ' ) {
    	  $('input_select_1').value = 'MN';
      }
    });

    Bob
    wibadd 04 Feb, 2012
    Thanks Bob. I tweaked it a bit to remove the if statements and it works like a charm!

    window.addEvent('load', function() {
    $('country').value = 'USA';
    $('country').fireEvent('change');
    $('state_province').value = 'WI';
    });
    GreyHead 04 Feb, 2012
    Hi wibadd,

    Great, glad it's working. Just a little comment - without the if statements, if the page is republished then the drop-downs will go back to these settings and not to the previously selected values.

    Bob
    wibadd 06 Feb, 2012
    I appreciate the follow up note. I added them back in, but then it kept selecting Alabama because there was not blank in the list. I was going to change the IF to look for != 'WI' but then I was concerned that WI would always get set when the form is republished, so I just added a blank to the Dynamic Dropdown options. Unfortunately, that still allows the blank value to be selected by the user - definitely not an ideal solution.

    The other issue is if I mark the field (state_province) as required it always displays a validation error. Is there anyway to get around this?
    GreyHead 07 Feb, 2012
    Hi wibadd,

    It sounds as though your scripts need careful debugging. You should get rid of the spaces in your values, clean up any other glitches and then check through carefully to find out what is happening at each step.

    I don't follow the logic of having WI set as a default but then not using it as the default when you republish? I'm sure that you can code that but I'd need to think it through.

    Bob
    This topic is locked and no more replies can be posted.