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

State / Province / Region * required field is not working

Started by concap, February 14, 2013, 04:36:07 AM

Previous topic - Next topic

romatvirtue

Quote from: ChrisTDR on August 21, 2013, 12:17:43 PM
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:

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:

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

Quote from: ChrisTDR on August 21, 2013, 12:17:43 PM
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:

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:

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

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:


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


To make the state select box required change this to:


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

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

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

Quote from: Akarr on April 06, 2013, 13:48:40 PM
Quote from: concap on February 14, 2013, 04:36:07 AM
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

GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 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
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation