Hi,
i have this code from forum:
add_filter(
'hivepress/v1/forms/listing_update/errors',
function( $errors, $form ) {
$listing = $form->get_model();
if ( $listing && ! $listing->get_image__id() ) {
$errors[] = 'Please upload at least one image.';
}
return $errors;
},
100,
2
);
add_filter(
'hivepress/v1/forms/listing_update',
function( $form ) {
$form['fields']['images']['statuses']['optional'] = null;
return $form;
},
1000
);
i want to add a checkbox validation but the $primary_checked is always null regardless if I tick the check boxor not
add_filter(
'hivepress/v1/forms/listing_update/errors',
function( $errors, $form ) {
$listing = $form->get_model();
if ( $listing && ! $listing->get_image__id() ) {
$errors[] = 'Please upload at least one image.';
}
$primary_checked = $listing->get_primarychecked();
if (!$primary_checked) {
$errors[] = 'You need to choose at least one number';
}
return $errors;
},
1000,
2
);
i can’t use required on the checkbox attribute because i have several checboxes and at least one must be checked so I need to have the validation in errors hook.
And i can’t use checkboxes (plural).