FormToggle.vue 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <template>
  2. <div class="field" :class="{ 'pt-3' : hasOffset }">
  3. <label class="label" v-html="label"></label>
  4. <div class="is-toggle buttons">
  5. <label class="button is-dark" :disabled="isDisabled" v-for="choice in choices" :class="{ 'is-link' : form[fieldName] === choice.value }">
  6. <input type="radio" class="is-hidden" :checked="form[fieldName] === choice.value" :value="choice.value" v-model="form[fieldName]" v-on:change="$emit(fieldName, form[fieldName])" :disabled="isDisabled" />
  7. <font-awesome-icon :icon="['fas', choice.icon]" v-if="choice.icon" class="mr-3" /> {{ choice.text }}
  8. </label>
  9. </div>
  10. <field-error :form="form" :field="fieldName" />
  11. <p class="help" v-html="help" v-if="help"></p>
  12. </div>
  13. </template>
  14. <script>
  15. export default {
  16. name: 'FormToggle',
  17. data() {
  18. return {
  19. }
  20. },
  21. props: {
  22. label: {
  23. type: String,
  24. default: ''
  25. },
  26. fieldName: {
  27. type: String,
  28. default: '',
  29. required: true
  30. },
  31. choices: {
  32. type: Array,
  33. required: true
  34. },
  35. form: {
  36. type: Object,
  37. required: true
  38. },
  39. help: {
  40. type: String,
  41. default: ''
  42. },
  43. hasOffset: {
  44. type: Boolean,
  45. default: false
  46. },
  47. isDisabled: {
  48. type: Boolean,
  49. default: false
  50. }
  51. }
  52. }
  53. </script>