Checkbox.vue 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <!--
  2. Case à cocher
  3. @see https://vuetifyjs.com/en/components/checkboxes/
  4. -->
  5. <template>
  6. <v-container
  7. class="px-0"
  8. fluid
  9. >
  10. <v-checkbox
  11. :model-value="modelValue"
  12. :value="modelValue"
  13. :label="$t(fieldLabel)"
  14. :disabled="readonly"
  15. :error="error || !!fieldViolations"
  16. :error-messages="errorMessage || fieldViolations ? $t(fieldViolations) : ''"
  17. @update:model-value="onUpdate($event)"
  18. @change="onChange($event)"
  19. />
  20. </v-container>
  21. </template>
  22. <script setup lang="ts">
  23. import {useFieldViolation} from "~/composables/form/useFieldViolation";
  24. const props = defineProps({
  25. modelValue: {
  26. type: Boolean,
  27. required: false
  28. },
  29. field: {
  30. type: String,
  31. required: false,
  32. default: null
  33. },
  34. label: {
  35. type: String,
  36. required: false,
  37. default: null
  38. },
  39. readonly: {
  40. type: Boolean,
  41. required: false
  42. },
  43. error: {
  44. type: Boolean,
  45. required: false
  46. },
  47. errorMessage: {
  48. type: String,
  49. required: false,
  50. default: null
  51. }
  52. })
  53. const {fieldViolations, updateViolationState} = useFieldViolation(props.field)
  54. const fieldLabel: string = props.label ?? props.field
  55. const emit = defineEmits(['update:model-value', 'change'])
  56. const onUpdate = (event: string) => {
  57. emit('update:model-value', props.modelValue)
  58. }
  59. const onChange = (event: Event | undefined) => {
  60. updateViolationState(event)
  61. emit('change', props.modelValue)
  62. }
  63. </script>
  64. <style scoped>
  65. </style>