FormField.vue 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <script setup>
  2. import { useIdGenerator } from '@/composables/helpers'
  3. defineOptions({
  4. inheritAttrs: false
  5. })
  6. const { inputId } = useIdGenerator(props.inputType, props.fieldName)
  7. const props = defineProps({
  8. modelValue: [String, Number, Boolean],
  9. label: {
  10. type: String,
  11. default: ''
  12. },
  13. fieldName: {
  14. type: String,
  15. default: '',
  16. required: true
  17. },
  18. fieldError: [String],
  19. inputType: {
  20. type: String,
  21. default: 'text'
  22. },
  23. placeholder: {
  24. type: String,
  25. default: ''
  26. },
  27. help: {
  28. type: String,
  29. default: ''
  30. },
  31. hasOffset: {
  32. type: Boolean,
  33. default: false
  34. },
  35. isDisabled: {
  36. type: Boolean,
  37. default: false
  38. },
  39. maxLength: {
  40. type: Number,
  41. default: null
  42. }
  43. })
  44. </script>
  45. <template>
  46. <div class="field" :class="{ 'pt-3' : hasOffset }">
  47. <label :for="inputId" class="label" v-html="$t(label)"></label>
  48. <div class="control">
  49. <input
  50. :disabled="isDisabled"
  51. :id="inputId"
  52. :type="inputType"
  53. class="input"
  54. :value="modelValue"
  55. :placeholder="placeholder"
  56. v-bind="$attrs"
  57. v-on:change="$emit('update:modelValue', $event.target.value)"
  58. :maxlength="maxLength"
  59. />
  60. </div>
  61. <FieldError v-if="fieldError != undefined" :error="fieldError" :field="fieldName" />
  62. <p class="help" v-html="$t(help)" v-if="help"></p>
  63. </div>
  64. </template>