From ab3d361d46d1ccae79c6508c2fd7fe0b89951c22 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 25 Jul 2026 11:13:52 +0800 Subject: [PATCH] =?UTF-8?q?fix(admin):=20accept=20multi-value=20=E5=8F=91?= =?UTF-8?q?=E5=B8=83=E7=B1=BB=E5=9E=8B=20on=20header-nav=20save?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit header_newposts_types is multi-select but PHP schema used type=select, so validate() rejected arrays with 422. Use checkbox and allow select+multiple arrays in SchemaProvider. --- .../src/schema/sections/page-display/index.js | 2 +- src/AKSRT/Admin/Schema/SchemaPageDisplay.php | 2 +- src/AKSRT/Admin/SchemaProvider.php | 15 ++++++++++++++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/assets/admin/src/schema/sections/page-display/index.js b/assets/admin/src/schema/sections/page-display/index.js index c7e317e4..0e0f45f3 100644 --- a/assets/admin/src/schema/sections/page-display/index.js +++ b/assets/admin/src/schema/sections/page-display/index.js @@ -134,7 +134,7 @@ export const pageDisplaySchemas = { { label: '紫色', value: 'jb-purple' }, { label: '粉色', value: 'jb-pink' }, ], dependsOn: { key: 'header_newposts_enabled', value: true } }, - { key: 'header_newposts_types', label: '发布类型', type: 'select', multiple: true, default: ['post'], options: [ + { key: 'header_newposts_types', label: '发布类型', type: 'checkbox', default: ['post'], options: [ { label: '文章', value: 'post' }, { label: '帖子', value: 'topic' }, { label: '商品', value: 'product' }, diff --git a/src/AKSRT/Admin/Schema/SchemaPageDisplay.php b/src/AKSRT/Admin/Schema/SchemaPageDisplay.php index 0e324064..390a0b6c 100644 --- a/src/AKSRT/Admin/Schema/SchemaPageDisplay.php +++ b/src/AKSRT/Admin/Schema/SchemaPageDisplay.php @@ -58,7 +58,7 @@ class SchemaPageDisplay { ['label' => '紫色', 'value' => 'jb-purple'], ['label' => '粉色', 'value' => 'jb-pink'], ]], - ['key' => 'header_newposts_types', 'label' => '发布类型', 'type' => 'select', 'default' => ['post'], 'options' => [ + ['key' => 'header_newposts_types', 'label' => '发布类型', 'type' => 'checkbox', 'default' => ['post'], 'options' => [ ['label' => '文章', 'value' => 'post'], ['label' => '帖子', 'value' => 'topic'], ['label' => '商品', 'value' => 'product'], diff --git a/src/AKSRT/Admin/SchemaProvider.php b/src/AKSRT/Admin/SchemaProvider.php index 091dbdb6..72ba7f42 100644 --- a/src/AKSRT/Admin/SchemaProvider.php +++ b/src/AKSRT/Admin/SchemaProvider.php @@ -181,13 +181,26 @@ class SchemaProvider { if (in_array($type, ['select', 'radio'], true) && !empty($field['options'])) { $valid_values = array_column($field['options'], 'value'); - if (!in_array($value, $valid_values, true)) { + // Multi-select: accept array values when schema.multiple is set + // (legacy / SPA may still use type=select multiple). + if (!empty($field['multiple']) && is_array($value)) { + foreach ($value as $item) { + if (!in_array($item, $valid_values, true)) { + $errors[] = sprintf('%s has an invalid value', $field['label'] ?? $key); + break; + } + } + } elseif (!in_array($value, $valid_values, true)) { $errors[] = sprintf('%s has an invalid value', $field['label'] ?? $key); } } if ($type === 'checkbox' && !empty($field['options'])) { $valid_values = array_column($field['options'], 'value'); + if (!is_array($value)) { + $errors[] = sprintf('%s must be an array', $field['label'] ?? $key); + continue; + } foreach ((array) $value as $item) { if (!in_array($item, $valid_values, true)) { $errors[] = sprintf('%s has an invalid value', $field['label'] ?? $key);