I have a formly-form with icon addon wrapper. i want to get fields value when user clicked icon of that field.
Look in Addon wrapper there is icon and onClick call showFile funtion and there want to get which field of form icon clicked with that field value.
fields: FormlyFieldConfig[] = [
{
key: 'input',
type: 'input',
templateOptions: {
label: 'name',
addonRight: {
icon:'remove_red_eye',
},
},
},
}
Form
<form [formGroup]="form">
<formly-form [model]="model" [fields]="fields" [form]="form"></formly-form>
</form>
Addon wrapper
import { Component, TemplateRef, ViewChild, AfterViewInit } from '@angular/core';
import { FieldWrapper } from '@ngx-formly/core';
@Component({
selector: 'formly-wrapper-addons',
template: `
<ng-container #fieldComponent></ng-container>
<ng-template #matSuffix>
<span
*ngIf="to.addonRight"
[ngStyle]="{cursor: to.addonRight.onClick ? 'pointer' : 'inherit'}"
(click)="addonRightClick($event)"
>
<mat-icon *ngIf="to.addonRight.icon" type="button" (click)="showFile($event)">{{ to.addonRight.icon }}</mat-icon>
<span *ngIf="to.addonRight.text">{{ to.addonRight.text }}</span>
</span>
</ng-template>
`,
})
export class FormlyWrapperAddons extends FieldWrapper implements AfterViewInit {
@ViewChild('matSuffix') matSuffix: TemplateRef<any>;
ngAfterViewInit() {
if (this.matSuffix) {
Promise.resolve().then(() => this.to.suffix = this.matSuffix);
}
}
addonRightClick($event: any) {
if (this.to.addonRight.onClick) {
this.to.addonRight.onClick(this.to, this, $event);
}
}
showFile($event:any){
//here i got mouse event
//want to know which field of form icon clicked with input value
console.log($event)
}
}