0c9ea page break validation (#455)

* fix password reset bug

* page break precognition validation

* precognition validation tests

---------

Co-authored-by: Julien Nahum <julien@nahum.net>
This commit is contained in:
Favour Olayinka
2024-06-24 10:08:54 +01:00
committed by GitHub
parent 3b5b8f4e3b
commit f40b95977d
4 changed files with 117 additions and 4 deletions

View File

@@ -110,6 +110,7 @@
:theme="theme"
class="mt-2 px-8 mx-1"
@click.stop="nextPage"
:loading="dataForm.busy"
>
{{ currentFieldsPageBreak.next_btn_text }}
</open-form-button>
@@ -442,9 +443,17 @@ export default {
return false
},
nextPage() {
this.currentFieldGroupIndex += 1
window.scrollTo({top: 0, behavior: 'smooth'})
return false
const fieldsToValidate = this.currentFields.map(f => f.id)
this.dataForm.busy = true
this.dataForm.validate('POST', '/forms/' + this.form.slug + '/answer', {}, fieldsToValidate)
.then((data) => {
this.currentFieldGroupIndex += 1
this.dataForm.busy = false
window.scrollTo({top: 0, behavior: 'smooth'})
}).catch(err => {
this.dataForm.busy = false
})
return false;
},
isFieldHidden(field) {
return (new FormLogicPropertyResolver(field, this.dataFormValue)).isHidden()

View File

@@ -146,6 +146,43 @@ class Form {
})
}
validate(method, url, config = {}, fieldsToValidate = {}) {
this.startProcessing()
const headers = {
'Precognition': true,
'Precognition-Validate-Only': Array.from(fieldsToValidate).join(),
...config.headers
}
config = {
body: {},
params: {},
url: url,
method: method,
headers,
...config,
}
if (method.toLowerCase() === "get") {
config.params = { ...this.data(), ...config.params }
} else {
config.body = { ...this.data(), ...config.data }
if (hasFiles(config.data) && !config.transformRequest) {
config.transformRequest = [(data) => serialize(data)]
}
}
return new Promise((resolve, reject) => {
opnFetch(config.url, config)
.then((data) => {
this.finishProcessing()
resolve(data)
})
.catch((error) => {
this.handleErrors(error)
reject(error)
})
})
}
handleErrors(error) {
this.busy = false