Search code examples
angularteradata-covalent

How to set values for TdDynamicFormsComponent in teradata covalent


I want to set values in the form on my edit page then i can be able to edit.

public formElements = [
    {
      name: 'market',
      type: TdDynamicElement.Input,
      label: 'market',
      required: true,
      flex: 50
    },
    {
      name: 'commodity',
      type: TdDynamicElement.Input,
      required: true,
      flex: 50,
      label: 'Commodity'
    },
    {
      name: 'time',
      label: 'Time',
      type: TdDynamicElement.Datepicker,
      required: true,
      flex: 50
    }
  ];

I want to add value like this <input type='text' value='some name'/>

Thanks

Edited. this is how i display the form in html

<mat-card>
  <mat-card-content>
    <h5>Add an Market</h5>

    <td-dynamic-forms #formRest [elements]="formElements">
    </td-dynamic-forms>

    <button mat-raised-button color="accent" (click)="submit()">Save</button>
    <button mat-raised-button color="warn" (click)="close()">Cancel</button>
  </mat-card-content>
</mat-card>

Solution

  • The Covalent Dynamic Forms has a default property on the form element interface. You can use that to set an initial value. It does not automatically update the form though if the array does not change.

    {
      "name": "text",
      "type": "text",
      "required": false,
      "default": "Default",
      "flex": 50
    },
    

    See this used in the following Stackblitz