FormTextarea.vue 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <script setup>
  2. import { useIdGenerator, useValidationErrorIdGenerator } from '@/composables/helpers'
  3. defineOptions({
  4. inheritAttrs: false
  5. })
  6. const props = defineProps({
  7. modelValue: [String, Number, Boolean],
  8. label: {
  9. type: String,
  10. default: ''
  11. },
  12. fieldName: {
  13. type: String,
  14. default: '',
  15. required: true
  16. },
  17. fieldError: [String],
  18. placeholder: {
  19. type: String,
  20. default: ''
  21. },
  22. help: {
  23. type: String,
  24. default: ''
  25. },
  26. size: {
  27. type: String,
  28. default: ''
  29. },
  30. hasOffset: {
  31. type: Boolean,
  32. default: false
  33. },
  34. isDisabled: {
  35. type: Boolean,
  36. default: false
  37. },
  38. maxLength: {
  39. type: Number,
  40. default: null
  41. },
  42. isIndented: Boolean,
  43. leftIcon: '',
  44. rightIcon: '',
  45. idSuffix: {
  46. type: String,
  47. default: ''
  48. }
  49. })
  50. const { inputId } = useIdGenerator(props.inputType, props.fieldName + props.idSuffix)
  51. const { valErrorId } = useValidationErrorIdGenerator(props.fieldName)
  52. const legendId = useIdGenerator('legend', props.fieldName).inputId
  53. </script>
  54. <template>
  55. <div class="mb-3" :class="{ 'pt-3' : hasOffset, 'is-flex' : isIndented }">
  56. <div v-if="isIndented" class="mx-2 pr-1" :style="{ 'opacity': isDisabled ? '0.5' : '1' }">
  57. <FontAwesomeIcon class="has-text-grey" :icon="['fas', 'chevron-right']" transform="rotate-135"/>
  58. </div>
  59. <div class="field" :class="{ 'is-flex-grow-5' : isIndented }">
  60. <label v-if="label" :for="inputId" class="label" v-html="$t(label)"></label>
  61. <div class="control" :class="{ 'has-icons-left' : leftIcon, 'has-icons-right': rightIcon }">
  62. <textarea
  63. :disabled="isDisabled"
  64. :id="inputId"
  65. class="textarea"
  66. :class="size"
  67. :value="modelValue"
  68. :placeholder="placeholder"
  69. v-bind="$attrs"
  70. v-on:input="$emit('update:modelValue', $event.target.value)"
  71. v-on:change="$emit('change:modelValue', $event.target.value)"
  72. :maxlength="maxLength"
  73. :aria-describedby="help ? legendId : undefined"
  74. :aria-invalid="fieldError != undefined"
  75. :aria-errormessage="fieldError != undefined ? valErrorId : undefined"
  76. />
  77. </div>
  78. <FieldError v-if="fieldError != undefined" :error="fieldError" :field="fieldName" />
  79. <p :id="legendId" class="help" v-html="$t(help)" v-if="help"></p>
  80. </div>
  81. </div>
  82. </template>