VirtueMart Forum

VirtueMart 2 + 3 + 4 => Administration & Configuration => Topic started by: winzor on January 11, 2013, 00:29:10 AM

Title: Require State Not Working
Post by: winzor on January 11, 2013, 00:29:10 AM
I have upgraded to the latest version of Virtuemart (2.0.18a).  I have the State field set to "required" but at checkout if a customer forgets they are still allowed to checkout with no pop up reminder like the one for Country.  Is there a proper fix for this?  Doing a Google search I found this, http://srihosting.com/blog/2012/09/virtuemart-2-require-state-at-checkout/  (http://srihosting.com/blog/2012/09/virtuemart-2-require-state-at-checkout/)  but I have no idea where to place this code.  I've tried a few places but it hasn't worked.  Below is the code in case the url is removed.


/* the following function checks whether the state should be required and either applies or removes the required class */
function requireState() {
  if(jQuery("select#virtuemart_state_id optgroup option").length < 2) {
    jQuery("select#virtuemart_state_id").removeClass('required invalid') /* if there are no state options also remove the invalid class in case the user has changed the country */
  } else {
    jQuery("select#virtuemart_state_id").addClass('required')
  }
}

jQuery(document).ready(function(){
  setTimeout(requireState, 500) /* after the page has loaded wait .5 seconds before applying the fix so virtuemart will finish adding in the states */
  jQuery("select#virtuemart_state_id, select#virtuemart_country_id").change(function() { /* if user changes state our country field reconsider if state should be required */
    requireState();
  });
});


Any help would be much appreciated.  If this has already been answered, point me too the thread and if it works I will pay you $20 USD.
Title: Re: Require State Not Working
Post by: winzor on February 04, 2013, 01:11:31 AM
Anybody?  Still looking for solution.  Can anyone help me?  I can afford a small fee if needed
Title: Re: Require State Not Working
Post by: jetdeck on February 17, 2013, 01:48:44 AM
This is a problem for me too...anybody??
Title: Re: Require State Not Working
Post by: diogodac on March 24, 2013, 17:33:34 PM
I have the exactly same problem here...
Title: Re: Require State Not Working
Post by: wbauer74 on May 28, 2013, 17:02:39 PM
Anyone know where to put the code that the OP listed? This is a bug and needs to be addressed. The solution is in the topic but just need to know what page to drop that code snippet in. Thanks
Title: Re: Require State Not Working
Post by: wazowski on August 05, 2013, 16:49:36 PM
You have to insert the code mentionned below into a JS script files and name it: "stateRequiredFix.js"

And then insert this line of code

<script src="<?php echo $this->baseurl ?>/templates/<?php echo $this->template ?>/js/stateRequiredFix.js" type="text/javascript"></script>

before the </body> tag of your Joomla template index.php file.
Title: Re: Require State Not Working
Post by: hotrod on January 19, 2014, 03:47:49 AM
Joomla! 2.5.11
VM 2.0.22a
PHP Version    5.3.3
Site www.hnctruckparts.com

Can someone tell me where to put the .js file   This issue has become a big problem for us when we are taxing by state and they don't fill in the state and they should have been taxed.
Title: Re: Require State Not Working
Post by: John2400 on January 20, 2014, 14:44:59 PM
I think you can over come this by setting a range in your zip code settings.  I was able to purchase a good on my own store by not setting a range on my shipping. Then when I got to the zip code I simply hit the space bar.
I could not do this and had to type a real number when I set a range in the shipping.