News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

Require State Not Working

Started by winzor, January 11, 2013, 00:29:10 AM

Previous topic - Next topic

winzor

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/   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.

winzor

Anybody?  Still looking for solution.  Can anyone help me?  I can afford a small fee if needed

jetdeck

This is a problem for me too...anybody??

diogodac

I have the exactly same problem here...

wbauer74

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

wazowski

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.

hotrod

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.
Bronze Member
VirtueMart 4.2.4 10922
Joomla!  ‎4.3.4
PHP 8.0

John2400

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.