FormField.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <template>
  2. <div class="field" :class="{ 'pt-3' : hasOffset }">
  3. <label :for="this.inputId(inputType,fieldName)" class="label" v-html="label"></label>
  4. <div class="control">
  5. <input
  6. :disabled="isDisabled"
  7. :id="this.inputId(inputType,fieldName)"
  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. <field-error :form="form" :field="fieldName" />
  18. <p class="help" v-html="help" v-if="help"></p>
  19. </div>
  20. </template>
  21. <script>
  22. export default {
  23. name: 'FormField',
  24. inheritAttrs: false,
  25. data() {
  26. return {
  27. }
  28. },
  29. props: {
  30. label: {
  31. type: String,
  32. default: ''
  33. },
  34. fieldName: {
  35. type: String,
  36. default: '',
  37. required: true
  38. },
  39. inputType: {
  40. type: String,
  41. default: 'text'
  42. },
  43. form: {
  44. type: Object,
  45. required: true
  46. },
  47. placeholder: {
  48. type: String,
  49. default: ''
  50. },
  51. help: {
  52. type: String,
  53. default: ''
  54. },
  55. hasOffset: {
  56. type: Boolean,
  57. default: false
  58. },
  59. isDisabled: {
  60. type: Boolean,
  61. default: false
  62. },
  63. maxLength: {
  64. type: Number,
  65. default: null
  66. }
  67. }
  68. }
  69. </script>