We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 21417
    • 486 Posts
    Hello,

    Wondering if someone can please help me with an eform selectbox issue related to Country / State required fields in an Evo 1.2.1 / eForm 1.4.8 site.

    I have 2 things I am stuck on...

    1. How do I make a select box a required field in eform? I want the person to select one country like in the select box below.
         <select id="select-test" name="select-test" eform_options="Select Country::1:Please select your country">
          <option disabled selected hidden value=""> -- select an option -- </option>
    	  <option value="Australia">Australia</option>
          <option value="New Zealand">New Zealand</option>
          <option value="UK">UK</option>
         </select>


    2. And then if they select Australia, they are shown another select box in eform that is also required (but dependent on the first select box) that lists the States of Australia. (this only applies to Australia. No state selectbox required for other countries)

    Any ideas?
    [ed. note: nickf08 last edited this post 6 years, 11 months ago.]
      Web design Adelaide
      http://gocreate.com.au
      • 17301
      • 932 Posts
        ■ email: [email protected] | ■ website: https://alienbuild.uk

        The greatest compliment you can give back to us, is to spend a few seconds leaving a rating at our trustpilot: https://uk.trustpilot.com/review/alienbuild.uk about the service we provided. We always drop mention of services offered by businesses we've worked with in the past to those of interest.
        • 21417
        • 486 Posts
        Thanks LK. That looks interesting. If I had more complex state needs I would definitely use it but I only need states for Australia and I have already manually created those fields. I also have the javascript working to show the Australian states field if Australia is selected as the country.

        What I really need help with is the eform functionality - making a selectbox option a required field. I can't seem to get that working.

        Any ideas? [ed. note: nickf08 last edited this post 6 years, 11 months ago.]
          Web design Adelaide
          http://gocreate.com.au
          • 21417
          • 486 Posts
          #1 How do I make a select box a required field in eform has been achieved.
          Changing...
          eform_options="Select Country::1:Please select your country"

          to...
          eform="Select Country::1">

          fixed it.

          For #2 It looks like the Australian state selectbox can't be a required field from the outset. I think I need to use jQuery to add the following to the state select tag if Australia is selected as the country:
          eform="Australian State::1"

          Currently looking on how to do that.
            Web design Adelaide
            http://gocreate.com.au
            • 21417
            • 486 Posts
            For #2 If Australia is selected in the required Country selectbox, show Australian States select box and make this required, else show nothing / require nothing...

            I am trying something like this in jquery:
            	$('#stateAU').hide();
            	$('#country').bind('change', function (e) {
            		if( $('#country').val() == 'AU') {
            			$('#state-au').attr('eform','Australian State::1');
            			$('#stateAU').slideToggle('fast');
            		}
            		else {
            			$('#state-au').removeAttr('eform');		
            			$('#stateAU').hide();
            		}
            	}).trigger('change');


            but eform does not seem to listen to the jquery to make "#state-au" a required field

            FYI: The html for the state select box looks like so...
            <div id="stateAU" class="row selectHider">
             <label class="spacer">Australian State*</label>
             <div class="row opt">
               <select id="state-au" name="state-au">
                 <option disabled selected hidden value=""> -- select an option -- </option>
                 <option value="ACT">ACT</option>
                 <option value="NSW">NSW</option>
                 <option value="NT">NT</option>
                 <option value="QLD">QLD</option>
                 <option value="SA">SA</option>
                 <option value="TAS">TAS</option>
                 <option value="VIC">VIC</option>
                 <option value="WA">WA</option>
                </select>
             </div>
            </div>


            Any ideas? [ed. note: nickf08 last edited this post 6 years, 11 months ago.]
              Web design Adelaide
              http://gocreate.com.au
              • 17301
              • 932 Posts
              Assuming you're using HTML5 you can just do this:

              <select id="state-au" name="state-au" required>
                ■ email: [email protected] | ■ website: https://alienbuild.uk

                The greatest compliment you can give back to us, is to spend a few seconds leaving a rating at our trustpilot: https://uk.trustpilot.com/review/alienbuild.uk about the service we provided. We always drop mention of services offered by businesses we've worked with in the past to those of interest.
                • 21417
                • 486 Posts
                Hmmmmm.... That doesn't seem to do anything for me. Thanks for the suggestion
                  Web design Adelaide
                  http://gocreate.com.au
                  • 13226
                  • 953 Posts
                  Quote from: lkfranklin at May 23, 2017, 06:09 AM
                  <select id="state-au" name="state-au" required>

                  I don't think this would work anyway, as the form will always require that something is selected before it processes the form, this is only for Australia but in this form of use it will still be required for all the rest as it's a required field

                  Would it not be possible to use "IF" ?

                  If "Autralia" then "display areas" - not sure how to code it myself, but the logic is there [ed. note: iusemodx last edited this post 6 years, 11 months ago.]
                    • 21417
                    • 486 Posts
                    Quote from: iusemodx at May 23, 2017, 09:19 AM
                    Quote from: lkfranklin at May 23, 2017, 06:09 AM
                    <select id="state-au" name="state-au" required="">

                    I don't think this would work anyway, as the form will always require that something is selected before it processes the form, this is only for Australia but in this form of use it will still be required for all the rest as it's a required field

                    Would it not be possible to use "IF" ?

                    If "Autralia" then "display areas" - not sure how to code it myself, but the logic is there</select>

                    Agreed re required given the dependency.

                    I wish. I started writing an If statement to insert the eform="Select Country::1" part, but got stuck with how to represent it. Basically if - select#select-test option is Australia - then - eform="Select Country::1" - but I also think this would not work because the IF call would be processed before the page is displayed. That's where I was thinking javascript would be needed - because the dependency only happens after the page is loaded. Its a real tricky one.
                      Web design Adelaide
                      http://gocreate.com.au
                      • 17301
                      • 932 Posts
                      Well..

                      Why not just have both input fields required but the state select set to hidden, with a default value selected, and then show this select box if Aus is selected?
                        ■ email: [email protected] | ■ website: https://alienbuild.uk

                        The greatest compliment you can give back to us, is to spend a few seconds leaving a rating at our trustpilot: https://uk.trustpilot.com/review/alienbuild.uk about the service we provided. We always drop mention of services offered by businesses we've worked with in the past to those of interest.