fix wpcfto select and repeater related visibility and validation
This commit is contained in:
17
vendor/wpcfto/metaboxes/assets/js/metaboxes.js
vendored
17
vendor/wpcfto/metaboxes/assets/js/metaboxes.js
vendored
@@ -126,9 +126,18 @@
|
||||
if ($boxChild.hasClass('repeater')) {
|
||||
// Repeater parent label (the field label for the repeater itself)
|
||||
const parentLabel = ($boxChild.find('.wpcfto-field-aside__label span:first-child').first().text() || '').trim();
|
||||
|
||||
// checker for the parent itself
|
||||
if($boxChild.find('.wpcfto-repeater-single').length == 0){
|
||||
|
||||
// Determine if this repeater is required.
|
||||
// We prefer presence of the hidden proxy input (rendered only when required).
|
||||
// Fallback: a data attribute marker if used by templates.
|
||||
const isRequiredRepeater = (
|
||||
$boxChild.find('.wpcfto-required-proxy').length > 0 ||
|
||||
$boxChild.is('[data-required="true"]')
|
||||
);
|
||||
|
||||
// Parent-level empty check: only flag when the repeater itself is required
|
||||
const hasRows = $boxChild.find('.wpcfto-repeater-single').length > 0;
|
||||
if (isRequiredRepeater && !hasRows) {
|
||||
invalid.push({
|
||||
id: fieldId,
|
||||
tab: tabTitle,
|
||||
@@ -137,6 +146,7 @@
|
||||
});
|
||||
}
|
||||
|
||||
// Child-level checks: scan only inputs that explicitly declare [required]
|
||||
$boxChild.find('.wpcfto-repeater-single').each(function (idx) {
|
||||
const $item = $(this);
|
||||
|
||||
@@ -156,6 +166,7 @@
|
||||
}
|
||||
if (!repeaterLabel) repeaterLabel = `Item #${idx+1}`;
|
||||
|
||||
// Only required child fields should be considered invalid when empty
|
||||
$item.find('input, textarea, select').filter('[required]').each(function () {
|
||||
const $f = $(this);
|
||||
if (isRequiredEmpty($f)) {
|
||||
|
||||
Reference in New Issue
Block a user