Require Custom Field Radio Buttons and Checkbox Sets

billywhite4billywhite4 Member
in Help edited January 2012
Is there a special way to require radio buttons in the Checkout template? I've copied the way FC does the shipping options to no avail:

<label for="materials-shared" class="fc_radio">Yes
<input type="radio" name="materials-shared" value="Yes" class="materials-shared fc_radio fc_required" />
<label for="materials-shared" class="fc_radio">No
<input type="radio" name="materials-shared" value="No" class="materials-shared fc_radio fc_required" />
<label class="fc_error" style="display: none;" for="materials-shared">Please answer if materials will be shared.</label>

I'm able to require other fields by simply applying fc_required to the input, but radio buttons don't seem to work.

For checkboxes, how would I require a user to select at least one from a list of checkboxes? Applying fc_required to the input of a checkbox makes that individual box required. This may require a bunch of custom javascript. Regardless, here is my markup:

<h4>Select Your Region(s)*</h4>
<input type="checkbox" name="region" value="Boston" id="Boston" class="fc_required" />
<label for="region">Boston</label>
<input type="checkbox" name="region" value="Philadelphia" id="Philadelphia" class="fc_required" />
<label for="region">Philadelphia</label>
<input type="checkbox" name="region" value="Atlanta" id="Atlanta" class="fc_required" />
<label for="region">Atlanta</label>
<label class="fc_error" style="display: none;" for="region">Please select your region(s).</label>
  • brettbrett FoxyCart Team
    To require one of many checkboxes, we don't have validation functions for that, though it's something we'll definitely keep in mind.

    To require a radio button though... I think that the .fc_required didn't used to work with radios but that we added it in a recent version. We'll take a look, but what version are you testing this on?
  • fc_adamfc_adam FoxyCart Team
    Required validation for radio buttons is added in version 0.7.2 - and your code above should work fine. Are you on version 0.7.2 currently?
  • Sweet! Thanks, guys. I didn't figure the checkbox validation would be built in since it's not really a common use of checkboxes. I did upgrade to 7.2 and that seems to have fixed the radio button .fc_required issue.
  • This got a bit strange. I upgraded to 7.2 at 4:45pm on Tuesday (1/10/2012) and tested a few orders, and all was well. Then this afternoon (1/12/2012) some time between 3:30pm and 4pm, the store went down completely. Turns out{store_name}/foxycart.complete.3.js was no longer available, a file the Sitemason integration expects. We rolled back to 7.1 and the store works fine.

    I didn't see any mention of this file version/location changing in the upgrade notes to 7.2. Do you know what might have changed? What's crazy is that it worked for two days. When upgrading, do config files (cached or otherwise) not get replaced/removed immediately if affected by the upgrade?

    And how should we be handling the location of foxycart.complete.3.js file? It's been working for 7.0 (min version supported by the Sitemason integration) & 7.1.
  • fc_adamfc_adam FoxyCart Team

    The includes files have actually updated in 0.7.2. It's noted in part in the changelog with this item:
    The default "sample code" has been upgraded to use jQuery 1.6.4 and Colorbox 1.3.18.
    After upgrading, you'll need to grab the latest includes from the sample code section of the administration and replace the ones already on your site.
  • lukeluke FoxyCart Team
    Sorry if that wasn't clear. We have it mentioned in the upgrade wiki also: We highly recommend hitting that page and reading it in detail before upgrading your store integration. Also worth noting, we have an API call now that you can use to fetch the latest FoxyCart includes which could be really helpful for your integration. It's not something you'll have to fetch with each page load (read: please, don't fetch it with each page load), but it is something you can use to update it, say, once a week or so. It's rare, but we did run into a situation previously where conflicts came up between colorbox and jquery and we had to make some changes (hence the complete.2.js an complete.3.js and such). We really hate making changes to already live stores, but sometimes we have to. Our approach has been to update the admin "sample code" section so that older stores can update themselves to the latest working setup and newer stores get the updated code out of the gate.

    Hope that all makes sense.
  • It does. Although I don't think I would have necessarily understood that location changed based on the upgrading notes (I promise I read them thoroughly!). What's concerning to me is that between the time we upgraded and when the store went down, we had 7 successful orders over two days. As well as my test orders after the upgrade. So there's no way we could have been the wiser getting false positives.

    If there's anyway to insure those files are removed when upgrading, that would be great so I can at least reliably know my tests are legitimate.

    It's not a big deal to stay at 7.1 for now and use custom js for form validation, but did want to point out our experience with the upgrade. We'll also look into grabbing that JS file through the API instead of expect it statically. Thanks as always for your responses. Best support in the industry!
  • lukeluke FoxyCart Team
    We definitely encourage people to upgrade since we're working hard to make these improvements. I'm not sure what could explain what you experienced other than our CDN not clearing correctly. We'll definitely look into it. It might also be that the browsers involved with the successful transactions had cached versions of those files. If we added a timestamp or version to each one, that might help avoid a cache-related issue and ensure the upgrade would test correctly and confidently. Thanks as always for your feedback.
Sign In or Register to comment.