FormField.vue 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. />
  15. </div>
  16. <field-error :form="form" :field="fieldName" />
  17. <p class="help" v-html="help" v-if="help"></p>
  18. </div>
  19. </template>
  20. <script>
  21. export default {
  22. name: 'FormField',
  23. inheritAttrs: false,
  24. data() {
  25. return {
  26. }
  27. },
  28. props: {
  29. label: {
  30. type: String,
  31. default: ''
  32. },
  33. fieldName: {
  34. type: String,
  35. default: '',
  36. required: true
  37. },
  38. inputType: {
  39. type: String,
  40. default: 'text'
  41. },
  42. form: {
  43. type: Object,
  44. required: true
  45. },
  46. placeholder: {
  47. type: String,
  48. default: ''
  49. },
  50. help: {
  51. type: String,
  52. default: ''
  53. },
  54. hasOffset: {
  55. type: Boolean,
  56. default: false
  57. },
  58. isDisabled: {
  59. type: Boolean,
  60. default: false
  61. }
  62. }
  63. }
  64. </script>