Edit modal, validation of whole data

This commit is contained in:
Juan Pablo Vial
2025-11-13 18:57:58 -03:00
parent 539ac3c0e8
commit a6037e4e14
8 changed files with 195 additions and 35 deletions

View File

@ -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) {