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..fba2cb38e 100644 --- a/docs/components/data/33-o-form.component.md +++ b/docs/components/data/33-o-form.component.md @@ -316,8 +316,35 @@ 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.form.isInInsertMode() && !data.name) { + errors.push('Name is required.'); + } + + 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 } +} +```