@bildvitta/quasar-ui-asteroid 3.0.0-beta.13 → 3.0.0-beta.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -355,6 +355,10 @@
355
355
  "description": "Altera ordem dos campos.",
356
356
  "type": "array"
357
357
  },
358
+ "qas-form-view/before-submit": {
359
+ "description": "Callback para controlar como funciona o comportamento do submit.",
360
+ "type": "function"
361
+ },
358
362
  "qas-form-view/cancel-button-label": {
359
363
  "description": "Rótulo do botão \"cancelar\".",
360
364
  "type": "string"
@@ -189,6 +189,7 @@
189
189
  },
190
190
  "qas-form-view": {
191
191
  "attributes": [
192
+ "before-submit",
192
193
  "cancel-button-label",
193
194
  "cancel-route",
194
195
  "custom-id",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@bildvitta/quasar-ui-asteroid",
3
3
  "description": "Asteroid",
4
- "version": "3.0.0-beta.13",
4
+ "version": "3.0.0-beta.14",
5
5
  "author": "Bild & Vitta <systemteam@bild.com.br>",
6
6
  "license": "MIT",
7
7
  "main": "dist/asteroid.cjs.min.js",
@@ -4,7 +4,7 @@
4
4
  <slot name="header" />
5
5
  </header>
6
6
 
7
- <q-form ref="form" @submit="submit">
7
+ <q-form ref="form" @submit="submitHandler">
8
8
  <slot />
9
9
 
10
10
  <slot v-if="useActions" name="actions">
@@ -122,6 +122,11 @@ export default {
122
122
  useSubmitButton: {
123
123
  default: true,
124
124
  type: Boolean
125
+ },
126
+
127
+ beforeSubmit: {
128
+ default: null,
129
+ type: Function
125
130
  }
126
131
  },
127
132
 
@@ -369,17 +374,35 @@ export default {
369
374
  })
370
375
  },
371
376
 
372
- async submit (event) {
373
- if (this.disable) return null
374
-
377
+ /**
378
+ * Se existe a propriedade com callback "beforeSubmit", então o controle de quando e como chamar o método "submit"
379
+ * está sendo controlado fora do QasFormView, se não existir a propriedade "beforeSubmit", então o controle do método
380
+ * submit é feito pelo próprio QasFormView, chamado pelo evento @submit.
381
+ */
382
+ submitHandler (event) {
375
383
  if (event) {
376
384
  event.preventDefault()
377
385
  }
378
386
 
387
+ const hasBeforeSubmit = typeof this.beforeSubmit === 'function'
388
+
389
+ if (hasBeforeSubmit) {
390
+ return this.beforeSubmit({
391
+ payload: { id: this.id, payload: this.modelValue, url: this.url },
392
+ resolve: payload => this.submit(payload)
393
+ })
394
+ }
395
+
396
+ this.submit()
397
+ },
398
+
399
+ async submit (externalPayload = {}) {
400
+ if (this.disable) return null
401
+
379
402
  this.isSubmitting = true
380
403
 
381
404
  try {
382
- const payload = { id: this.id, payload: this.modelValue, url: this.url }
405
+ const payload = { id: this.id, payload: this.modelValue, url: this.url, ...externalPayload }
383
406
 
384
407
  this.$qas.logger.group(
385
408
  `QasFormView - submit -> payload do ${this.entity}/${this.mode}`, [payload]
@@ -4,6 +4,12 @@ meta:
4
4
  desc: Componente para C.R.U.D. responsável pela pela criação (Create) e edição (Update).
5
5
 
6
6
  props:
7
+ before-submit:
8
+ desc: Callback para controlar como funciona o comportamento do submit.
9
+ default: null
10
+ type: Function
11
+ examples: ['beforeSubmit({ payload, resolve })']
12
+
7
13
  cancel-button-label:
8
14
  desc: Rótulo do botão "cancelar".
9
15
  default: Cancelar
@@ -261,13 +261,8 @@ export default {
261
261
  modelValue: {
262
262
  handler (value) {
263
263
  this.nested = extend(true, [], value)
264
- },
265
- immediate: true
266
- },
267
264
 
268
- field: {
269
- handler () {
270
- !this.modelValue.length && this.setDefaultNestedValue()
265
+ if (!this.nested.length) return this.setDefaultNestedValue()
271
266
  },
272
267
  immediate: true
273
268
  }