The Foxy forums are on the move!

We're in the process of moving our forums over to a new system, and so these forums are now read-only.
If you have a question about your store in the meantime, please don't hesitate to reach out to us via email.

"return false" in "if" block inside preprocess array

mwahahamwahaha Member
in Help edited August 2012
I had an earlier version of this page working just fine, although the code was unmaintainably bloated. Now I'm going back through it, making it DRYer, re-factoring, and I just can't get this part to work.

I'm doing a simple validation on add-to-cart. There are a bunch of groups of radio buttons. In order to add-to-cart, the user must check one within each group, or get a colorbox "alert" reminding him he's missed something.

I've refactored the old validation code into an "each" function, with a second "if" block inside. The FC docs say that "If any function in the preprocess array returns false, the cart-add is aborted," but that doesn't seem to be happening here with my each() function.

Everything is logging correctly in the console, but the add-to-cart is still happening.

Here's the relevant code:, arr) {
    var href = '';
    if (e.tagName == 'A') {
        href = e.href;
    } else if (e.tagName == 'FORM') {
        href = 'https://'+storedomain+'/cart?'+jQuery(e).serialize();
    if (!href.match("cart=(view|checkout)") && !href.match("redirect=")) {
    	$('.options').each(function() {
	    	var errorText = "Oops! Please choose a " + $(this).data('name') + "!";
    		if(!$(this).find('input[type=radio]:checked').length) {
    		    console.log("no checkbox was checked!");
    		    $.colorbox({fixed:true, html:"<p class='warning-prompt'>" + errorText + "</p>"});
    		    return false;

I would whisper the live page now, but I get the red prompt "You must choose at least one recipient" when I try to comment with the "whisper" box checked. So I guess I have to wait for someone to reply first?
  • fc_adamfc_adam FoxyCart Team

    When you click the whisper checkbox, another input should appear below it - you'll need to type in the usernames of the people you're whispering to, comma separated. If you could whisper the live page to me, that would be awesome!
  • lukeluke FoxyCart Team
    I think your return false is actually returning from the anonymous function() definition within each(), not from the preprocess function. Dealing with anonymous functions can be tricky, but you may need a global flag of some kind you can trigger the return false with outside of the each().
  • Thanks for your patience, Luke. You're right, of course. I came back and finally got this going correctly.
Sign In or Register to comment.