FormCheckbox.vue 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <script setup>
  2. defineOptions({
  3. inheritAttrs: false
  4. })
  5. const props = defineProps({
  6. modelValue: Boolean,
  7. fieldName: {
  8. type: String,
  9. default: '',
  10. required: true
  11. },
  12. label: {
  13. type: String,
  14. default: ''
  15. },
  16. labelClass: {
  17. type: String,
  18. default: ''
  19. },
  20. help: {
  21. type: String,
  22. default: ''
  23. },
  24. })
  25. const emit = defineEmits(['update:modelValue'])
  26. const attrs = useAttrs()
  27. const checked = ref(props.modelValue)
  28. function setCheckbox() {
  29. if (attrs['disabled'] == undefined) {
  30. emit('update:modelValue', checked)
  31. }
  32. }
  33. </script>
  34. <template>
  35. <div class="field">
  36. <input :id="fieldName" type="checkbox" :name="fieldName" class="is-checkradio is-info" v-model="checked" v-on:change="setCheckbox" v-bind="$attrs"/>
  37. <label tabindex="0" :for="fieldName" class="label" :class="labelClass" v-html="$t(label)" v-on:keypress.space.prevent="setCheckbox" />
  38. <p class="help" v-html="$t(help)" v-if="help" />
  39. </div>
  40. </template>