FormField.vue 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <template>
  2. <div class="field" :class="{ 'pt-3' : hasOffset }">
  3. <label :for="inputId" class="label" v-html="label"></label>
  4. <div class="control">
  5. <input
  6. :disabled="isDisabled"
  7. :id="inputId"
  8. :type="inputType"
  9. class="input"
  10. v-model="form[fieldName]"
  11. :placeholder="placeholder"
  12. v-bind="$attrs"
  13. v-on:change="$emit('field-changed', form[fieldName])"
  14. :maxlength="this.maxLength"
  15. />
  16. </div>
  17. <FieldError :form="form" :field="fieldName" />
  18. <p class="help" v-html="help" v-if="help"></p>
  19. </div>
  20. </template>
  21. <script>
  22. import { useIdGenerator } from '../../composables/helpers'
  23. export default {
  24. name: 'FormField',
  25. inheritAttrs: false,
  26. setup(props) {
  27. const { inputId } = useIdGenerator(props.inputType, props.fieldName)
  28. return { inputId }
  29. },
  30. data() {
  31. return {
  32. }
  33. },
  34. props: {
  35. label: {
  36. type: String,
  37. default: ''
  38. },
  39. fieldName: {
  40. type: String,
  41. default: '',
  42. required: true
  43. },
  44. inputType: {
  45. type: String,
  46. default: 'text'
  47. },
  48. form: {
  49. type: Object,
  50. required: true
  51. },
  52. placeholder: {
  53. type: String,
  54. default: ''
  55. },
  56. help: {
  57. type: String,
  58. default: ''
  59. },
  60. hasOffset: {
  61. type: Boolean,
  62. default: false
  63. },
  64. isDisabled: {
  65. type: Boolean,
  66. default: false
  67. },
  68. maxLength: {
  69. type: Number,
  70. default: null
  71. }
  72. }
  73. }
  74. </script>