import { Component, ViewChild, inject } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { YelonFormModule, SFComponent, SFSchema } from '@yelon/form';
import { NzButtonModule } from 'ng-zorro-antd/button';
import { NzGridModule } from 'ng-zorro-antd/grid';
import { NzInputModule } from 'ng-zorro-antd/input';
import { NzMessageService } from 'ng-zorro-antd/message';
import { NzQRCodeModule } from 'ng-zorro-antd/qr-code';
@Component({
selector: 'form-custom-simple',
template: `
<sf #sf [schema]="schema" (formSubmit)="submit($event)">
<ng-template sf-template="formName" let-i let-ui="ui" let-schema="schema">
<div nz-row>
<div nz-col>
<input
nz-input
[attr.id]="i.id"
[disabled]="i.disabled"
[attr.disabled]="i.disabled"
[nzSize]="i.size"
[ngModel]="i.value"
(ngModelChange)="i.setValue($event)"
/>
</div>
<div nz-col>
<button nz-button type="button" nzType="link" (click)="updateQr()">{{ ui.btnText }}</button>
</div>
</div>
</ng-template>
<ng-template sf-template="qr" let-i let-ui="ui" let-schema="schema">
<nz-qrcode [nzValue]="i.value" />
</ng-template>
</sf>
`,
standalone: true,
imports: [YelonFormModule, FormsModule, NzGridModule, NzInputModule, NzButtonModule, NzQRCodeModule]
})
export class FormCustomSimpleComponent {
private readonly msg = inject(NzMessageService);
@ViewChild('sf') readonly sf!: SFComponent;
schema: SFSchema = {
properties: {
formName: {
type: 'string',
title: 'Custom Title',
ui: {
widget: 'custom',
btnText: 'Update Qr'
},
default: 'test'
},
qr: {
type: 'string',
ui: {
widget: 'custom'
},
default: 'https://ng.yunzainfo.com'
}
}
};
updateQr(): void {
const formNameValue = this.sf.getProperty('/formName')?.value;
const qr = this.sf.getProperty('/qr');
qr?.setValue(formNameValue, true);
this.msg.info(`Suc`);
}
submit(value: {}): void {
this.msg.success(JSON.stringify(value));
}
}