Two delivery date required fields, make one OR other required (Java if, else if, else statement help)

Highlighted
Shopify Expert
195 0 25

Hi Katie,

Here is javascript to manage the showing and hiding of the various inputs:

(function($) {

  var DeliveryDateManager = function() {
		
    this.local = $("#localDeliveryContainer");
    this.national = $("#nationalDeliveryContainer");

    this.registerEventListener = function() {
	  var _this = this;
	  var deliverySelect = $("select.clickCollectLocation").first();
	  deliverySelect.on( "change", function() {
	    var optionText = deliverySelect.find("option:selected").text();
		if (/local/i.test(optionText)) {
		  _this.showOnlyLocal();
		} else if (/national/i.test(optionText)) {
		  _this.showOnlyNational();
		} else {
		  _this.hideNationalAndLocal();
		}
	  });
	};

    this.showOnlyLocal= function() {
	  this.local.show();
	  this.national.hide();
	};

    this.showOnlyNational = function() {
	  this.local.hide();
	  this.national.show();
	};

    this.hideNationalAndLocal = function() {
	  this.local.hide();
	  this.national.hide();
	};

    this.start = function() {
	  this.hideNationalAndLocal();
	  this.registerEventListener();
	}
  }

  var manager = new DeliveryDateManager();
  manager.start();

})(jQuery)

If you want to get ride of the lines, <hr> elements, place them in the containers as I have described above.

Cheers,
Ryan

Stop Stressing About Shopify You’ve Got Better Things To Do => https://320ny.com/shopify/
0 Likes
Highlighted
Shopify Partner
20 0 0

Hi Ryan

Am I right to save this as a seperate js file and call in to the cart page 

i.e.    {{ 'showhide.js' | asset_url | script_tag }}

I've named the js file as 'showhide' 

 

0 Likes
Highlighted
Shopify Partner
20 0 0

It's just it isnt working!! Thank you 

0 Likes
Highlighted
Shopify Expert
9887 100 1728

You've not copied Ryan's code correctly. Looking at the script you've got it's missing the opening bracket:

(

As a sidenote, it looks like that clickcollect script has an error in it too.

★ Winning Partner of the Build a Business competition. ★ http://freakdesign.com.au
0 Likes
Highlighted
Shopify Partner
20 0 0

yes I corrected that it still doesn't work, thank you for trying though

as for click and collect file,  everything was working fine (as it should) I'm not sure what the error is i'll look into this now.....

0 Likes
Highlighted
Shopify Expert
195 0 25

Hi Katie,

I don't see that file on your site. 

You also need to place this file below the script that loads jQuery. It's safe to put in your theme below the other loading scripts. 

-Ryan

Stop Stressing About Shopify You’ve Got Better Things To Do => https://320ny.com/shopify/
0 Likes