Skip to content

Commit

Permalink
Set char limit on rich text
Browse files Browse the repository at this point in the history
  • Loading branch information
chiragchhatrala committed Jan 7, 2025
1 parent cc62f61 commit 8a41e0f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
26 changes: 24 additions & 2 deletions client/components/forms/RichTextAreaInput.client.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,29 @@
/>
</div>

<template #help>
<template
v-if="$slots.help"
#help
>
<slot name="help" />
</template>
<template #error>

<template
v-if="maxCharLimit && showCharLimit"
#bottom_after_help
>
<small :class="theme.default.help">
{{ charCount }}/{{ maxCharLimit }}
</small>
</template>

<template
v-if="$slots.error"
#error
>
<slot name="error" />
</template>

<MentionDropdown
v-if="enableMentions && mentionState"
:state="mentionState"
Expand All @@ -59,6 +76,7 @@ import registerMentionExtension from '~/lib/quill/quillMentionExtension.js'
const props = defineProps({
...inputProps,
maxCharLimit: { type: Number, required: false, default: null },
editorOptions: {
type: Object,
default: () => ({})
Expand Down Expand Up @@ -110,6 +128,10 @@ const quillOptions = computed(() => {
return mergedOptions
})
const charCount = computed(() => {
return compVal.value ? compVal.value.replace(/<[^>]*>/g, '').trim().length : 0
})
</script>

<style lang="scss">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@
@update:model-value="onFieldHelpPositionChange"
/>

<template v-if="['text', 'number', 'url', 'email'].includes(field.type)">
<template v-if="['text', 'rich_text', 'number', 'url', 'email'].includes(field.type)">
<text-input
name="max_char_limit"
native-type="number"
Expand Down Expand Up @@ -841,6 +841,9 @@ export default {
multi_lines: false,
max_char_limit: 2000
},
rich_text: {
max_char_limit: 2000
},
email: {
max_char_limit: 2000
},
Expand Down

0 comments on commit 8a41e0f

Please sign in to comment.