Set char limit on rich text (#662)

* Set char limit on rich text

* richtext placeholder
This commit is contained in:
Chirag Chhatrala
2025-01-14 15:57:37 +05:30
committed by GitHub
parent 72d139e2af
commit 06c35121a0
2 changed files with 29 additions and 4 deletions

View File

@@ -30,17 +30,33 @@
v-model="compVal"
:options="quillOptions"
:disabled="disabled"
:placeholder="placeholder"
:style="inputStyle"
/>
</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"
@@ -59,6 +75,7 @@ import registerMentionExtension from '~/lib/quill/quillMentionExtension.js'
const props = defineProps({
...inputProps,
maxCharLimit: { type: Number, required: false, default: null },
editorOptions: {
type: Object,
default: () => ({})
@@ -86,6 +103,7 @@ if (props.enableMentions && !Quill.imports['blots/mention']) {
const quillOptions = computed(() => {
const defaultOptions = {
placeholder: props.placeholder || '',
theme: 'snow',
modules: {
toolbar: [
@@ -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">