Skip to content

Commit

Permalink
Clean up empty HTML and help text in form inputs (#700)
Browse files Browse the repository at this point in the history
* Clean up empty HTML and help text in form inputs

* Update api/app/Http/Requests/UserFormRequest.php

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

---------

Co-authored-by: Julien Nahum <julien@nahum.net>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Feb 14, 2025
1 parent c819e76 commit 82fae97
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
16 changes: 16 additions & 0 deletions api/app/Http/Requests/UserFormRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,22 @@
*/
abstract class UserFormRequest extends \Illuminate\Foundation\Http\FormRequest
{
protected function prepareForValidation()
{
$data = $this->all();

if (isset($data['properties']) && is_array($data['properties'])) {
$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);
}

/**
* Get the validation rules that apply to the request.
*
Expand Down
8 changes: 8 additions & 0 deletions client/components/forms/RichTextAreaInput.client.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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']) {
Expand Down

0 comments on commit 82fae97

Please sign in to comment.