Author Topic: State / Province / Region * required field is not working  (Read 33210 times)

romatvirtue

  • Jr. Member
  • **
  • Posts: 91
Re: State / Province / Region * required field is not working
« Reply #15 on: January 26, 2014, 00:01:37 am »
Here's a solution that may solve some people's problems. I am using a template, that does not have any over-riding files for User.

I found that in components/com_virtuemart/views/user/tmpl/edit_address.php - there is a section that reads:

Code: [Select]
function callValidatorForRegister(f){

        var elem = jQuery('#username_field');
        elem.attr('class', "required");

        var elem = jQuery('#name_field');
        elem.attr('class', "required");

        var elem = jQuery('#password_field');
        elem.attr('class', "required");

        var elem = jQuery('#password2_field');
        elem.attr('class', "required");

        var elem = jQuery('#userForm');

The last line containing: #userForm appears to attempt to validate the whole userform (the fields below Username and Password)

I changed this to name each field individually like this:

Code: [Select]
function callValidatorForRegister(f){

        var elem = jQuery('#username_field');
        elem.attr('class', "required");

        var elem = jQuery('#name_field');
        elem.attr('class', "required");

        var elem = jQuery('#password_field');
        elem.attr('class', "required");

        var elem = jQuery('#password2_field');
        elem.attr('class', "required");

        var elem = jQuery('#first_name');
elem.attr('class', "required");

var elem = jQuery('#last_name');
elem.attr('class', "required");

var elem = jQuery('#address_1');
elem.attr('class', "required");

var elem = jQuery('#zip');
elem.attr('class', "required");

var elem = jQuery('#city');
elem.attr('class', "required");

var elem = jQuery('#virtuemart_country_id');
elem.attr('class', "required");

var elem = jQuery('#virtuemart_state_id');
elem.attr('class', "required");

(you may be using more fields that this - the field names can be found in the 'Shopper Fields' configuration area of the backend) - just start each with '#'

This works for me, I know this because when I click 'Register' on an empty form, all the required fields that have validation appear with a yellow highlight and this now includes the State field.

Hope this helps people.

Hello! I tried your solution, but this did not work for me... :(

romatvirtue

  • Jr. Member
  • **
  • Posts: 91
Re: State / Province / Region * required field is not working
« Reply #16 on: January 26, 2014, 08:16:42 am »
Here's a solution that may solve some people's problems. I am using a template, that does not have any over-riding files for User.

I found that in components/com_virtuemart/views/user/tmpl/edit_address.php - there is a section that reads:

Code: [Select]
function callValidatorForRegister(f){

        var elem = jQuery('#username_field');
        elem.attr('class', "required");

        var elem = jQuery('#name_field');
        elem.attr('class', "required");

        var elem = jQuery('#password_field');
        elem.attr('class', "required");

        var elem = jQuery('#password2_field');
        elem.attr('class', "required");

        var elem = jQuery('#userForm');

The last line containing: #userForm appears to attempt to validate the whole userform (the fields below Username and Password)

I changed this to name each field individually like this:

Code: [Select]
function callValidatorForRegister(f){

        var elem = jQuery('#username_field');
        elem.attr('class', "required");

        var elem = jQuery('#name_field');
        elem.attr('class', "required");

        var elem = jQuery('#password_field');
        elem.attr('class', "required");

        var elem = jQuery('#password2_field');
        elem.attr('class', "required");

        var elem = jQuery('#first_name');
elem.attr('class', "required");

var elem = jQuery('#last_name');
elem.attr('class', "required");

var elem = jQuery('#address_1');
elem.attr('class', "required");

var elem = jQuery('#zip');
elem.attr('class', "required");

var elem = jQuery('#city');
elem.attr('class', "required");

var elem = jQuery('#virtuemart_country_id');
elem.attr('class', "required");

var elem = jQuery('#virtuemart_state_id');
elem.attr('class', "required");

(you may be using more fields that this - the field names can be found in the 'Shopper Fields' configuration area of the backend) - just start each with '#'

This works for me, I know this because when I click 'Register' on an empty form, all the required fields that have validation appear with a yellow highlight and this now includes the State field.

Hope this helps people.

My bad. I deleted
Code: [Select]
var elem = jQuery('#userForm');
Now everything works great. What I noticed is that, this solution only works for "Register and Checkout" and not for "Checkout as Guest." I just called the "callValidatorForRegister" function for "Checkout as Guest" button as well. Thanks for your solution.

craftyweb

  • Beginner
  • *
  • Posts: 31
    • web design
Re: State / Province / Region * required field is not working
« Reply #17 on: April 01, 2014, 18:01:11 pm »
The problem here seems to be that the state select box is not getting the class of 'required'.

The bug lies in 'Administrator > com_virtuemart > helpers > shopfunctions.php'

Line 354 (in VirtueMart 2.0.26d) sets the required attribute but not the required class:

Code: [Select]
if ($required != 0) {
$attrs .= ' required';
}
$attrs .= ' class="vm-chzn-select"';

To make the state select box required change this to:

Code: [Select]
if ($required != 0) {
$attrs .= ' required class="vm-chzn-select required"';
} else {
$attrs .= ' class="vm-chzn-select"';
}
Joomla: 2.5.20
VirtueMart 2.0.26d

Milbo

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 10158
  • VM3.9 Eagle Owl
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: State / Province / Region * required field is not working
« Reply #18 on: April 02, 2014, 15:13:55 pm »
almost right, but

if a country has no state, the whole thing must be unrequired. Best is just to test the new vm2.5.5, it should work directly there.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

craftyweb

  • Beginner
  • *
  • Posts: 31
    • web design
Re: State / Province / Region * required field is not working
« Reply #19 on: April 11, 2014, 13:04:23 pm »
Thanks Milbo,

I don't have any active countries which don't have states. so that wouldn't be a problem on my sites.

Joomla: 2.5.20
VirtueMart 2.0.26d

michelabraham

  • Beginner
  • *
  • Posts: 1
Re: State / Province / Region * required field is not working
« Reply #20 on: October 08, 2014, 16:55:35 pm »
G'day,
when filling up billing address information, condition for required field 'State / Province / Region' is skipped. Which means that when customer leaves 'State / Province / Region' on default value = -Select- then Customer is not notified about required field and form gets saved.

I've checked that Configuration->shoper fields virtuemart_state_id Required is checked.
Joomla2.5.9 VM2.0.18a

Anybody knows what is wrong?

in shopper field list disable the virtuemart_state_id and that should do the trick. if your shop is outside US and dont need the US states

Hello,
Thank you for this topic who can really help me. I want to remove the state fields because I live in France but I don't know where to delete this.
Akarr or anyone else, can you give me the road to in my ftp. I looked for days now.
Thank you very much
Michel

GJC Web Design

  • 3rd party VirtueMart Developer
  • Super Hero
  • *
  • Posts: 10356
  • Virtuemart, Joomla & php developer
    • GJC Web Design
  • VirtueMart Version: 3.6.8
Re: State / Province / Region * required field is not working
« Reply #21 on: October 09, 2014, 11:11:41 am »
Just unpublish in your VM shopper fields admin
GJC Web Design
VirtueMart and Joomla Developers - php developers http://www.gjcwebdesign.com
VM3 AusPost Shipping Plugin - e-go Shipping Plugin - VM3 Postcode Shipping Plugin - Radius Shipping Plugin - VM3 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
http://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation