Checkbox.vue 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. v-model="data"
  12. :value="data"
  13. :label="$t(fieldLabel)"
  14. :disabled="readonly"
  15. :error="error || !!violation"
  16. :error-messages="errorMessage || violation ? $t(violation) : ''"
  17. @change="onChange($event)"
  18. />
  19. </v-container>
  20. </template>
  21. <script setup lang="ts">
  22. import {useFieldViolation} from "~/composables/form/useFieldViolation";
  23. const props = defineProps({
  24. field: {
  25. type: String,
  26. required: false,
  27. default: null
  28. },
  29. label: {
  30. type: String,
  31. required: false,
  32. default: null
  33. },
  34. data: {
  35. type: Boolean,
  36. required: false
  37. },
  38. readonly: {
  39. type: Boolean,
  40. required: false
  41. },
  42. error: {
  43. type: Boolean,
  44. required: false
  45. },
  46. errorMessage: {
  47. type: String,
  48. required: false,
  49. default: null
  50. }
  51. })
  52. const { emit } = useNuxtApp()
  53. const { violation, onChange } = useFieldViolation(props.field, emit)
  54. const fieldLabel = props.label ?? props.field
  55. </script>
  56. <style scoped>
  57. </style>