@WidgetComponent

nm-form-select

File

src/app/shared/widgets/form/select.component.ts

Metadata

selector nm-form-select
templateUrl ./select.component.html

Index

Widget inputs
Widget outputs
Properties
Methods

Constructor

constructor(halService: HalService)
Parameters :
Name Type Optional
halService HalService no

Methods

Protected configureWidget
configureWidget(configuration: WidgetConfig, _form: FormGroup, action: ActionForm)
Decorators : WidgetConfigure
Parameters :
Name Type Optional
configuration WidgetConfig no
_form FormGroup no
action ActionForm no
Returns : void
ngOnInit
ngOnInit()
Returns : void

Properties

Public group
group: FormGroup
Type : FormGroup
Public hidden
hidden: boolean
Type : boolean
Public multiple
multiple: boolean
Type : boolean
Default value : false
Public name
name: string
Type : string
Public options
options: any[]
Type : any[]
Public placeholder
placeholder: string
Type : string
Public required
required: boolean
Type : boolean
Public selectedValue
selectedValue: any
Type : any
import { Component } from "@angular/core";
import { FormControl, FormGroup, Validators } from "@angular/forms";
import { WidgetConfig } from "../widget.configuration";
import { WidgetComponent, WidgetConfigure } from "../widget.metadata";
import { ActionForm } from "../../components/hal/actionForm";
import { formProperty } from "../../components/hal/hal";
import { HalService } from "../../components/hal/hal.service";

@WidgetComponent("nm-form-select")
@Component({
  selector: "nm-form-select",
  templateUrl: "./select.component.html",
})
export class FormSelectComponent {
  public name: string;
  public group: FormGroup;
  public placeholder: string;
  public hidden: boolean;
  public required: boolean;
  public multiple: boolean = false;
  public options: any[];
  public selectedValue: any;

  constructor(private halService: HalService) {}

  @WidgetConfigure()
  protected configureWidget(
    configuration: WidgetConfig,
    _form: FormGroup,
    action: ActionForm
  ) {
    let name = configuration.configuration["name"];
    let prop;
    try {
      prop = formProperty(action, name);
    } catch (e) {
      return;
    }

    this.name = prop.name;
    this.hidden = prop.hidden || configuration.configuration["hidden"];
    this.placeholder =
      prop.description || configuration.configuration["placeholder"];
    this.required = prop.required || configuration.configuration["required"];

    if (configuration.configuration["multiple"]) {
      this.multiple = configuration.configuration["multiple"];
    }

    this.halService.suggestObservable(prop.suggest).subscribe((options) => {
      this.options = options;
    });

    this.group = _form;

    let control = prop.required
      ? new FormControl(prop.value)
      : new FormControl(prop.value, Validators.required);
    this.group.addControl(this.name, control);
    this.group.patchValue({ name: this.selectedValue });
  }

  ngOnInit() {}
}
<div [formGroup]="group" *ngIf="name">
  <mat-form-field [class.hidden]="hidden == true">
    <mat-select
      style="width: 100%"
      [(ngModel)]="selectedValue"
      [placeholder]="placeholder | translate"
      [formControlName]="name"
      [id]="name"
      [multiple]="multiple"
      [required]="required"
    >
      <mat-option *ngFor="let option of options" [value]="option.value">
        {{ option.label | translate }}
      </mat-option>
    </mat-select>
  </mat-form-field>
</div>
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""