- if you disabled your state/region field
- a new required field was added (either manually or automatically), in our case it was TOS field
- saving user or vendor in VM backend gives a javascript error (in js console) and breaks the submission (you cannot save the data)
this is how to fix it:
locate this file:
\administrator\components\com_virtuemart\helpers\vmjsapi.php
and update the whole function to this:
- Code: Select all
static public function vmValidator ($guest=null){
if(!isset($guest)){
$guest = JFactory::getUser()->guest;
}
// Implement Joomla's form validation
JHtml::_ ('behavior.formvalidation'); //j2
//JHtml::_('behavior.formvalidator'); //j3
$regfields = array('username', 'name');
if($guest){
$regfields[] = 'password';
$regfields[] = 'password2';
}
$jsRegfields = implode("','",$regfields);
$js = "function myValidator(f, r) {
var regfields = ['".$jsRegfields."'];
var requ = '';
if(r == true){
requ = 'required';
}
if (typeof jQuery == 'undefined') return true;
for (i = 0; i < regfields.length; i++) {
var elem = jQuery('#'+regfields[i]+'_field');
elem.attr('class', requ);
}
if (document.formvalidator.isValid(f)) {
if (jQuery('#recaptcha_wrapper').is(':hidden') && (r == true)) {
jQuery('#recaptcha_wrapper').show();
} else {
return true; //sents the form, we dont use js.submit()
}
} else {
//dirty Hack for country dropdown
var cField = jQuery('#virtuemart_country_id');
if(cField.length > 0){
if(cField.attr('required')=='required' && cField.attr('aria-required')=='true'){
var chznField = jQuery('#virtuemart_country_id_chzn');
if (chznField.length > 0) {
var there = chznField.attr('class');
var ind = there.indexOf('required');
var results = 0;
if(cField.attr('aria-invalid')=='true' && ind==-1){
chznField.attr('class', there + ' required');
results = 2;
} else if(ind!=-1){
var res = there.slice(0,ind);
chznField.attr('class', res);
}
chznField = jQuery('#virtuemart_state_id_chzn');
if (chznField.length > 0) {
if(results===0){
results = chznField.find('.chzn-results li').length;
}
there = chznField.attr('class');
ind = there.indexOf('required');
var sel = jQuery('#virtuemart_state_id').val();
if(sel==0 && ind==-1 && results>1){
chznField.attr('class', there + ' required');
} else if(ind!=-1 && (results<2 || sel!=0)){
var res = there.slice(0,ind);
chznField.attr('class', res);
}
}
}
}
}
if (jQuery('#recaptcha_wrapper').is(':hidden') && (r == true)) {
jQuery('#recaptcha_wrapper').show();
}
var msg = '" .addslashes (vmText::_ ('COM_VIRTUEMART_MISSING_REQUIRED_JS'))."';
alert(msg + ' ');
}
return false;
}";
vmJsApi::addJScript('vm.validator',$js);
}
best regards, stan