Hey,
take a look here:
hidden link
when editing the play, try to add some text to the "play description", then scroll to the bottom and press save.
the error that popsup is that you need to check at leaset 1 genre - but there are already a few genres checked.
any ideas?
thanks!
update: after updating toolset plugins and wpml plugins + unlocking cred form in wpml settings as "translatable" - error is gone.
nope - it now just sometimes works and sometimes doesn't. very confusing.
Nigel
Supporter
Languages:
English (English )
Spanish (Español )
Timezone:
Europe/London (GMT+00:00)
Hi Ido
I visited the link.
To see the problem I should be editing this post with a Toolset Form, is that right?
I presumably need access credentials to edit the posts, let me mark your next reply as private so you can provide them.
You say it sometimes works and sometimes doesn't. Do you have a specific post where it consistently doesn't work?
Nigel
Supporter
Languages:
English (English )
Spanish (Español )
Timezone:
Europe/London (GMT+00:00)
Hi Ido
You are using some custom code to make the genre taxonomy required, would that be right?
What/where is it?
hey,
all code is in functions.php
i think the relevant code starts in line 378
thanks!
ido
hey again,
sorry - validation code is in:
\library\js\scripts.js:
/*************play forms validation**************/
jQuery('#cred_form_1964_1, #cred_form_1971_1').submit(function(){
return validateForm();
});
validateForm=function() {
var genreFlag = false;
var premiereFlag = false;
var charactersFlag = false;
jQuery('#cred_form_1964_1_wpcf-total_select option, #cred_form_1971_1_wpcf-total_select option').each(function(){
if(jQuery(this).attr('selected')) {
//alert(jQuery(this).text())
if(jQuery(this).text()!='none') {
charactersFlag = true;
}
}
})
if(jQuery('#cred_form_1964_1_wpcf-never-produced_1, #cred_form_1971_1_wpcf-never-produced_1').attr('checked') == 'checked' || jQuery('#cred_form_1964_1_wpcf-premiere-year, #cred_form_1971_1_wpcf-premiere-year').val()!="") {
premiereFlag = true;
}
jQuery('#cred_form_1964_1_genre input[type=checkbox], #cred_form_1971_1_genre input[type=checkbox]').each(function(){
if(jQuery(this).attr('checked'))
genreFlag=true;
})
if(!premiereFlag) {
alert('אנא מלא את שנת הבכורה או סמן את תיבת "לא הופק מעולם"');
return false;
} else if(!genreFlag) {
alert("אנא סמן תיבת סימון אחת לפחות בקטגוריית הז'נר");
return false;
} else if(!charactersFlag) {
alert("אנא בחר את מספר הדמויות");
return false;
} else {
return true;
}
}
if(location.pathname=="/add-play-form/" || location.search=="?cred-edit-form=1964") {
jQuery(window).bind('beforeunload', function(){
var valid = validateForm();
if(!valid && (location.search == "?cred-edit-form=1964" || location.pathname == "/add-play-form/")){
return "לא כל שדות החובה מולאו, והמחזה לא יתעדכן/יתווסף. האם את/ה בטוח/ה שאת/ה רוצה לעזוב את העמוד?"
} else {
jQuery(window).unbind('beforeunload')
}
});
} else {
jQuery(window).unbind('beforeunload');
}
/*************END form validation**************/
Thanks!
Nigel
Supporter
Languages:
English (English )
Spanish (Español )
Timezone:
Europe/London (GMT+00:00)
Hi Ido
Sorry, I can't debug your custom JavaScript for you.
We have an API for form validation, and you can make taxonomies required by adding code such as the following to your theme's functions.php file:
function tssupp_require_genre($field_data, $form_data) {
// Split $field_data into separate $fields and $errors
list( $fields,$errors ) = $field_data;
// validate specific form
if ( $form_data['id'] == 123 ) {
// check if genre taxonomy set
if ( empty( $fields['genre']['value'] ) ) {
$errors['genre'] = 'You must select a genre';
}
}
return array($fields,$errors);
}
add_filter( 'cred_form_validate', 'tssupp_require_genre', 10, 2 );
Edit the form ID and the taxonomy slug as required.
If you can't get your JS solution to work I suggest you go with our API method.
thanks Nigel 🙂
ok - will do. should I use the same function for other custom fields validation?
Ido
Nigel
Supporter
Languages:
English (English )
Spanish (Español )
Timezone:
Europe/London (GMT+00:00)
You can bundle all of the validation for the same form into a single function, for taxonomies and for custom fields.
I'd suggest you error log $fields and $errors and $form_data so that you can see what it is you are working with.