feat(widgets): add phase 4 validation and accessibility

This commit is contained in:
2026-08-17 19:12:38 +08:00
parent 31e72748c3
commit 009b66326a
23 changed files with 8078 additions and 53 deletions
+4 -15
View File
@@ -2,6 +2,7 @@
'use strict';
const config = window.aksrtWidgetAdmin || {};
const core = window.AKSRTWidgetAdminCore;
function initForm(root) {
const $root = $(root);
@@ -68,15 +69,7 @@
$form.find('[name]').each(function () {
const rowIndexes = $(this).parents('.aksrt-widget-repeater__row').get().reverse().map((row) => Number(row.dataset.rowIndex || 0));
if (!rowIndexes.length) return;
let foundWidgetNumber = false;
let cursor = 0;
this.name = this.name.replace(/\[(\d+|__index_[a-f0-9]+__)\]/g, (match, index) => {
if (!foundWidgetNumber && /^\d+$/.test(index)) {
foundWidgetNumber = true;
return match;
}
return cursor < rowIndexes.length ? `[${rowIndexes[cursor++]}]` : match;
});
this.name = core.replaceRepeaterIndexes(this.name, rowIndexes);
});
}
@@ -89,14 +82,10 @@
function evaluateDependencies($form) {
$form.find('[data-dependency]').each(function () {
let rule;
try { rule = JSON.parse(this.dataset.dependency || '[]'); } catch (_error) { return; }
if (!Array.isArray(rule) || rule.length < 3) return;
const rule = core.parseDependency(this.dataset.dependency || '[]');
const $row = $(this).closest('.aksrt-widget-repeater__row');
const current = fieldValue($row.length ? $row : $form, String(rule[0]));
const expected = String(rule[2]);
const visible = rule[1] === '==' ? current === expected : current !== expected;
this.hidden = !visible;
this.hidden = !core.dependencyVisible(rule, current);
});
}