char count for textarea (#94)

Co-authored-by: Julien Nahum <julien@nahum.net>
This commit is contained in:
Chirag Chhatrala 2023-02-22 22:11:37 +05:30 committed by GitHub
parent 29c09d9ea2
commit 5a1bd0e0c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 21 additions and 4 deletions

View File

@ -11,10 +11,17 @@
class="resize-y"
:name="name" :style="inputStyle"
:placeholder="placeholder"
:maxlength="maxCharLimit"
/>
<small v-if="help" :class="theme.default.help">
<div v-if="help || showCharLimit" class="flex">
<small v-if="help" :class="theme.default.help" class="flex-grow">
<slot name="help">{{ help }}</slot>
</small>
<small v-else class="flex-grow"></small>
<small v-if="showCharLimit && maxCharLimit" :class="theme.default.help">
{{ charCount }}/{{ maxCharLimit }}
</small>
</div>
<has-error v-if="hasValidation" :form="form" :field="name" />
</div>
</template>
@ -24,6 +31,16 @@ import inputMixin from '~/mixins/forms/input.js'
export default {
name: 'TextAreaInput',
mixins: [inputMixin]
mixins: [inputMixin],
props: {
maxCharLimit: { type: Number, required: false, default: null },
showCharLimit: { type: Boolean, required: false, default: false },
},
computed: {
charCount() {
return (this.compVal) ? this.compVal.length : 0
}
}
}
</script>