From dab8b222e18642ba0f74862a45fd1ed1126482fc Mon Sep 17 00:00:00 2001 From: Chirag Chhatrala Date: Thu, 13 Feb 2025 15:31:49 +0530 Subject: [PATCH 1/2] Clean up empty HTML and help text in form inputs --- api/app/Http/Requests/UserFormRequest.php | 15 +++++++++++++++ .../components/forms/RichTextAreaInput.client.vue | 8 ++++++++ 2 files changed, 23 insertions(+) diff --git a/api/app/Http/Requests/UserFormRequest.php b/api/app/Http/Requests/UserFormRequest.php index f8b8da295..9e1ecbe96 100644 --- a/api/app/Http/Requests/UserFormRequest.php +++ b/api/app/Http/Requests/UserFormRequest.php @@ -14,6 +14,21 @@ */ abstract class UserFormRequest extends \Illuminate\Foundation\Http\FormRequest { + protected function prepareForValidation() + { + $data = $this->all(); + + if (isset($data['properties']) && is_array($data['properties'])) { + foreach ($data['properties'] as &$property) { + if (isset($property['help']) && strip_tags($property['help']) === '') { // Remove help if it's empty + $property['help'] = null; + } + } + } + + $this->merge($data); + } + /** * Get the validation rules that apply to the request. * diff --git a/client/components/forms/RichTextAreaInput.client.vue b/client/components/forms/RichTextAreaInput.client.vue index bf9f6a432..57aad7ae7 100644 --- a/client/components/forms/RichTextAreaInput.client.vue +++ b/client/components/forms/RichTextAreaInput.client.vue @@ -95,6 +95,14 @@ const emit = defineEmits(['update:modelValue']) const { compVal, inputStyle, hasError, inputWrapperProps } = useFormInput(props, { emit }) const editor = ref(null) const mentionState = ref(null) + +// Add this watch to clean up empty HTML content +watch(compVal, (val) => { + if (val && val.replace(/<[^>]*>/g, '').trim() === '') { + compVal.value = null + } +}, { immediate: true }) + // Move the mention extension registration to onMounted if (props.enableMentions && !Quill.imports['blots/mention']) { From 29108db28445dc893c4efca8fe4752d34aa1cbe8 Mon Sep 17 00:00:00 2001 From: Julien Nahum Date: Fri, 14 Feb 2025 15:14:43 +0000 Subject: [PATCH 2/2] Update api/app/Http/Requests/UserFormRequest.php Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- api/app/Http/Requests/UserFormRequest.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/api/app/Http/Requests/UserFormRequest.php b/api/app/Http/Requests/UserFormRequest.php index 9e1ecbe96..1ed971c24 100644 --- a/api/app/Http/Requests/UserFormRequest.php +++ b/api/app/Http/Requests/UserFormRequest.php @@ -19,11 +19,12 @@ protected function prepareForValidation() $data = $this->all(); if (isset($data['properties']) && is_array($data['properties'])) { - foreach ($data['properties'] as &$property) { - if (isset($property['help']) && strip_tags($property['help']) === '') { // Remove help if it's empty + $data['properties'] = array_map(function ($property) { + if (isset($property['help']) && is_string($property['help']) && strip_tags($property['help']) === '') { $property['help'] = null; } - } + return $property; + }, $data['properties']); } $this->merge($data);