AddEditUserDialog.vue 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <template>
  2. <q-dialog ref="dialogRef" @hide="onDialogHide">
  3. <q-card class="q-dialog-plugin">
  4. <DefaultDialogHeader :title="props.title" @close="onDialogCancel" />
  5. <q-card-section>
  6. <q-form ref="formRef" class="row q-col-gutter-sm">
  7. <q-input
  8. v-model="name"
  9. label="Nome"
  10. hint="Nome e sobrenome"
  11. :rules="[inputRules.required]"
  12. class="col-6"
  13. />
  14. <q-input
  15. v-model="email"
  16. label="Email"
  17. :rules="[inputRules.email]"
  18. class="col-6"
  19. />
  20. <q-input
  21. v-model="password"
  22. label="Senha"
  23. :rules="[inputRules.min(6)]"
  24. class="col-6"
  25. />
  26. </q-form>
  27. </q-card-section>
  28. <q-card-actions align="center">
  29. <q-btn color="primary" label="Cancel" @click="onDialogCancel" />
  30. <q-space />
  31. <q-btn color="primary" label="OK" @click="onOKClick" />
  32. </q-card-actions>
  33. </q-card>
  34. </q-dialog>
  35. </template>
  36. <script setup>
  37. import { ref } from "vue";
  38. import { inputRules } from "src/helpers/utils";
  39. import { useDialogPluginComponent } from "quasar";
  40. import DefaultDialogHeader from "src/components/geral/DefaultDialogHeader.vue";
  41. defineEmits([
  42. // REQUIRED; need to specify some events that your
  43. // component will emit through useDialogPluginComponent()
  44. ...useDialogPluginComponent.emits,
  45. ]);
  46. const props = defineProps({
  47. user: {
  48. type: Object,
  49. default: null,
  50. },
  51. title: {
  52. type: Function,
  53. default: () => "Adicionar Usuário",
  54. },
  55. });
  56. const { dialogRef, onDialogHide, onDialogOK, onDialogCancel } =
  57. useDialogPluginComponent();
  58. const formRef = ref(null);
  59. const name = ref(props.user?.name || "");
  60. const email = ref(props.user?.email || "");
  61. const password = ref("");
  62. // this is part of our example (so not required)
  63. const onOKClick = () => {
  64. if (!formRef.value.validate()) {
  65. return;
  66. }
  67. const payload = {
  68. name: name.value,
  69. email: email.value,
  70. password: password.value,
  71. };
  72. // on OK, it is REQUIRED to
  73. // call onDialogOK (with optional payload)
  74. onDialogOK({ ...payload });
  75. // or with payload: onDialogOK({ ... })
  76. // ...and it will also hide the dialog automatically
  77. };
  78. </script>