-
Notifications
You must be signed in to change notification settings - Fork 2
Forms
zehavibarak edited this page Dec 25, 2023
·
2 revisions
import { FormComponent, RecipientModel, ViewMode, BizDoc } from '@bizdoc/core';
@Component({
templateUrl: './my-form.component.html',
styleUrls: ['./my-form.component.scss']
})
@BizDoc({
selector: 'app-my-form'
})
export class MyFormComponent implements FormComponent<MyFormModel> {
readonly form = this.fb.group({
subject: this._fb.control([], [Validators.required])
});
mode: ViewMode;
constructor(private _fb: FormBuilder) {
}
onBind(model: RecipientModel<MyFormModel>): void {
}
}
interface MyFormModel {
subject: string;
}Add rules to form configuration using Architecture tool. Rules will show in bizdoc.json configuration file.
{
"Forms":[{
"Rules": [
{
"Name": "myField",
"Roles": [
"role1"
]
}
],
"Name": "myForm"
}]
}In form component, test s rule for a field or a section of html by adding bizdocDisabled or bizdocHidden directive.
<input bizdocDisabled="myField" />
...
<div bizdocHidden="myField"></div>You can gain programmatic access to rules from form component onBind() method.
onBind(data: RecipientModel<MyModel>): void {
if (!data.rules['myField']) {
...
}
}BizDoc logs changes made by users to documents model. Changes can then be viewed from document trace.
To enable a form to show version compare, use the bizdocCompareGroup, bizdocCompareContext and bizdocCompareName directives.
<ng-container [ngSwitch]="mode">
<div *ngSwitchCase='"version"'>
<span bizdocCompareName="from,to">{{data.model.from}} - {{data.model.to}}</span>
<table bizdocCompareGroup="lines">
<tr *ngFor='let line of data.model.lines' [bizdocCompareContext]='line'>
<td bizdocCompareName="product">{{line.product}}</td>
</tr>
</table>
</div>
</ng-container>You can access version data programmatically from the onBind() function.
onBind(data: RecipientModel<MyFormModel>, version?: MyFormModel): void {
if(version && version.subject !== data.model.subject) {
...
}
}Moding Ltd.