Edit modal, validation of whole data
This commit is contained in:
@ -30,7 +30,7 @@
|
||||
add() {
|
||||
const url = '/api/ventas/reservation/add'
|
||||
const form = document.getElementById(this.ids.form)
|
||||
const body = new FormData(form)
|
||||
let body = new FormData(form)
|
||||
const date = this.components.$date.calendar('get date')
|
||||
body.set(`${this.prefix}_date`, [date.getFullYear(), date.getMonth() + 1, date.getDate()].join('-'))
|
||||
body.set(`${this.prefix}_buyer_rut`, Rut.clean(this.components.rut.querySelector('input').value))
|
||||
@ -59,6 +59,18 @@
|
||||
body.delete(`${this.prefix}_buyer_email_name`)
|
||||
body.delete(`${this.prefix}_buyer_email_domain`)
|
||||
|
||||
body.keys().forEach(key => {
|
||||
if (body.get(key) === '') {
|
||||
body.delete(key)
|
||||
}
|
||||
})
|
||||
|
||||
body = this.validateBody(body)
|
||||
if (body.keys().toArray().length === 0) {
|
||||
alert('No hay datos.')
|
||||
return
|
||||
}
|
||||
|
||||
const method = 'post'
|
||||
return APIClient.fetch(url, {method, body}).then(response => response.json()).then(json => {
|
||||
if (json.success) {
|
||||
|
||||
Reference in New Issue
Block a user