From 3fda48916947c209467f5235f0e01373eb9daef6 Mon Sep 17 00:00:00 2001 From: "IMATIASL\\patricia.martinez" Date: Tue, 4 Feb 2025 13:49:49 +0100 Subject: [PATCH 1/2] New input form-data-validation-function --- _data/components/form.yml | 6 +++++ docs/components/data/33-o-form.component.md | 28 ++++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/_data/components/form.yml b/_data/components/form.yml index de15dfb84..c386946e5 100644 --- a/_data/components/form.yml +++ b/_data/components/form.yml @@ -180,6 +180,12 @@ attributes: [ required: "", since: "15.1.0", description: "Fields attr's order that ​​will be be set values in this order in the form, separated by ';'" +},{ + name: "form-data-validation-function", + type: "(data: any) => OFormValidation", + since: "15.4.2", + description: "Executes the before-save validation callback for insert and update operations." + }] outputs: [{ diff --git a/docs/components/data/33-o-form.component.md b/docs/components/data/33-o-form.component.md index b5ffd0ee1..f6a62f267 100644 --- a/docs/components/data/33-o-form.component.md +++ b/docs/components/data/33-o-form.component.md @@ -316,8 +316,34 @@ Ontimize web now supports the JDBC **UUID** sql type. To indicate that a key col ``` -## Set-value-orde rnew +## Set-value-ordernew The o-form doesn't guarantee the order in which the fields will be filled. If a field value is required by another one (as a parent-key of a form field, an error could be produced). In principle, the default filler should be right in most cases, but with this parameter the filler order can be established. It isn't necessary to establish every field attribute. The attributes specified in this parameter are filled first. + +## Input form-data-validation-function new + +**Ontimize Web** allows to execute the before-save validation callback for insert and update operations in `o-form`. + +If the validation fails, it displays an alert with the corresponding messages and prevents the operation from proceeding. + +```html + +``` +```ts +@ViewChild('form') form: OFormComponent; + +validateBeforeSave= (data: any): OFormValidation => { + + const errors: string[] = []; + + if (this. === 'insert' && !data.name) { + errors.push('Name is required.'); + } + if (action === 'update' && data.status === 'inactive') { + errors.push('Cannot update a record with inactive status.'); + } + return { valid: errors.length === 0, title:' Inactive status ',messages: errors } +} +``` From 70c9f526a8e5a8c2f05432299753358e775350d9 Mon Sep 17 00:00:00 2001 From: "IMATIASL\\patricia.martinez" Date: Wed, 5 Feb 2025 18:49:33 +0100 Subject: [PATCH 2/2] Fixed typo --- docs/components/data/33-o-form.component.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/components/data/33-o-form.component.md b/docs/components/data/33-o-form.component.md index f6a62f267..fba2cb38e 100644 --- a/docs/components/data/33-o-form.component.md +++ b/docs/components/data/33-o-form.component.md @@ -338,12 +338,13 @@ validateBeforeSave= (data: any): OFormValidation => { const errors: string[] = []; - if (this. === 'insert' && !data.name) { + if (this.form.isInInsertMode() && !data.name) { errors.push('Name is required.'); } - if (action === 'update' && data.status === 'inactive') { + + if (this.form.isInUpdateMode() && data.status === 'inactive') { errors.push('Cannot update a record with inactive status.'); } - return { valid: errors.length === 0, title:' Inactive status ',messages: errors } + return { valid: errors.length === 0, title: ' Inactive status ', messages: errors } } ```