feat: Developed markFieldAsRequired and isFieldRequired methods to mark and validate required form fields; added user alert if location information is not provided.

This commit is contained in:
Developer 02 2024-07-17 15:52:04 +02:00
parent f94728bf67
commit 14bd2e22fc
2 changed files with 30 additions and 4 deletions

View File

@ -106,6 +106,8 @@
readOnly: isMobile() readOnly: isMobile()
}) })
this.markFieldAsRequired(formFieldCity);
/** /**
* Date, post code and place label part * Date, post code and place label part
*/ */
@ -162,7 +164,7 @@
annotationIds: PSPDFKit.Immutable.List([annotation_city_label.id]), annotationIds: PSPDFKit.Immutable.List([annotation_city_label.id]),
value: "Ort", value: "Ort",
readOnly: true readOnly: true
}) })
return [annotation, formField, annotation_date, formFieldDate, annotation_city, formFieldCity, annotation_date_label, formFieldDateLabel, annotation_city_label, formFieldCityLabel] return [annotation, formField, annotation_date, formFieldDate, annotation_city, formFieldCity, annotation_date_label, formFieldDateLabel, annotation_city_label, formFieldCityLabel]
} }
@ -304,4 +306,14 @@
static inchToPoint(inch) { static inchToPoint(inch) {
return inch * 72 return inch * 72
} }
}
static #requiredFieldNames = new Array()
static markFieldAsRequired(formField) {
this.#requiredFieldNames.push(formField.name)
}
static isFieldRequired(formField) {
return this.#requiredFieldNames.includes(formField.name)
}
}

View File

@ -65,7 +65,7 @@ class App {
this.Instance.addEventListener("annotations.willChange", _ => { this.Instance.addEventListener("annotations.willChange", _ => {
Comp.ActPanel.Toggle(); Comp.ActPanel.Toggle();
}); });
// Load annotations into PSPDFKit // Load annotations into PSPDFKit
try { try {
@ -168,6 +168,20 @@ class App {
} }
async handleFinish(event) { async handleFinish(event) {
const iJSON = await this.Instance.exportInstantJSON()
const iFormFieldValues = await iJSON.formFieldValues;
const iReqFields = iFormFieldValues.filter(f => Annotation.isFieldRequired(f))
const hasEmptyReq = iReqFields.some(f => (f.value === undefined || f.value === null || f.value === ""))
if (hasEmptyReq){
Swal.fire({
title: 'Warnung',
text: 'Bitte füllen Sie alle Standortinformationen vollständig aus!',
icon: 'warning',
})
return false;
}
const validationResult = await this.validateAnnotations(this.signatureCount) const validationResult = await this.validateAnnotations(this.signatureCount)
if (validationResult === false) { if (validationResult === false) {
Swal.fire({ Swal.fire({
@ -204,7 +218,7 @@ class App {
// Export annotation data and save to database // Export annotation data and save to database
try { try {
const json = await this.Instance.exportInstantJSON() const json = await iJSON
const postEnvelopeResult = await this.Network.postEnvelope( const postEnvelopeResult = await this.Network.postEnvelope(
this.envelopeKey, this.envelopeKey,
this.currentDocument.id, this.currentDocument.id,