From 4bfc1fe9ae57c71f1ca052dc9b60f2615d2e15d4 Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Mon, 18 Nov 2024 12:54:21 +0000 Subject: [PATCH] Prevent comma completing tags when defining container validation rules --- .../js/components/fieldtypes/TagsFieldtype.vue | 14 +++++++++++++- resources/lang/en/fieldtypes.php | 1 + src/Fieldtypes/Taggable.php | 6 ++++++ .../CP/Assets/AssetContainersController.php | 1 + 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/resources/js/components/fieldtypes/TagsFieldtype.vue b/resources/js/components/fieldtypes/TagsFieldtype.vue index 17d652e75b..ff51919743 100644 --- a/resources/js/components/fieldtypes/TagsFieldtype.vue +++ b/resources/js/components/fieldtypes/TagsFieldtype.vue @@ -9,7 +9,7 @@ :multiple="true" :placeholder="__(config.placeholder)" :searchable="true" - :select-on-key-codes="[9, 13, 188]" + :select-on-key-codes="keyCodes" :taggable="true" :append-to-body="true" :value="value" @@ -72,6 +72,18 @@ export default { mixins: [Fieldtype, HasInputOptions], + computed: { + keyCodes() { + let keyCodes = [9, 13]; + + if (this.config.select_on_commas) { + keyCodes.push(188); + } + + return keyCodes; + }, + }, + methods: { focus() { this.$refs.input.focus(); diff --git a/resources/lang/en/fieldtypes.php b/resources/lang/en/fieldtypes.php index 7b0e375665..e147f54edc 100644 --- a/resources/lang/en/fieldtypes.php +++ b/resources/lang/en/fieldtypes.php @@ -172,6 +172,7 @@ 'table.title' => 'Table', 'taggable.config.options' => 'Provide pre-defined tags that can be selected.', 'taggable.config.placeholder' => 'Type and press ↩ Enter', + 'taggable.config.select_on_commas' => 'Should a comma automatically select the tag?', 'taggable.title' => 'Taggable', 'taxonomies.title' => 'Taxonomies', 'template.config.blueprint' => 'Adds a "map to blueprint" option. Learn more in the [documentation](https://statamic.dev/views#inferring-templates-from-entry-blueprints).', diff --git a/src/Fieldtypes/Taggable.php b/src/Fieldtypes/Taggable.php index 37ba11e89f..6fd8883dbb 100644 --- a/src/Fieldtypes/Taggable.php +++ b/src/Fieldtypes/Taggable.php @@ -26,6 +26,12 @@ protected function configFieldItems(): array 'type' => 'list', 'add_button' => __('Add Option'), ], + 'select_on_commas' => [ + 'display' => __('Select on Commas'), + 'instructions' => __('statamic::fieldtypes.taggable.config.select_on_commas'), + 'type' => 'toggle', + 'default' => true, + ], ]; } diff --git a/src/Http/Controllers/CP/Assets/AssetContainersController.php b/src/Http/Controllers/CP/Assets/AssetContainersController.php index 28e1995fe0..61024037ae 100644 --- a/src/Http/Controllers/CP/Assets/AssetContainersController.php +++ b/src/Http/Controllers/CP/Assets/AssetContainersController.php @@ -271,6 +271,7 @@ protected function formBlueprint($container = null) 'type' => 'taggable', 'display' => __('Validation Rules'), 'instructions' => __('statamic::messages.asset_container_validation_rules_instructions'), + 'select_on_commas' => false, ], ], ],