FormCheckbox.vue 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <template>
  2. <div class="field">
  3. <input :id="fieldName" type="checkbox" :name="fieldName" class="is-checkradio is-info" v-model="form[fieldName]" v-on:change="$emit(fieldName, form[fieldName])" v-bind="$attrs">
  4. <label tabindex="0" :for="fieldName" class="label" :class="labelClass" v-html="label" v-on:keypress.space.prevent="setCheckbox"></label>
  5. <p class="help" v-html="help" v-if="help"></p>
  6. </div>
  7. </template>
  8. <script>
  9. export default {
  10. name: 'FormCheckbox',
  11. inheritAttrs: false,
  12. data() {
  13. return {
  14. }
  15. },
  16. props: {
  17. label: {
  18. type: String,
  19. default: ''
  20. },
  21. labelClass: {
  22. type: String,
  23. default: ''
  24. },
  25. fieldName: {
  26. type: String,
  27. default: '',
  28. required: true
  29. },
  30. form: {
  31. type: Object,
  32. required: true
  33. },
  34. help: {
  35. type: String,
  36. default: ''
  37. },
  38. },
  39. methods: {
  40. setCheckbox(event) {
  41. if (this.$attrs.disabled == false) {
  42. this.form[this.fieldName] = !this.form[this.fieldName]
  43. this.$emit(this.fieldName, this.form[this.fieldName])
  44. }
  45. }
  46. }
  47. }
  48. </script>