1

How to configure form field required validation required or not using property file.

Eg: we have many form fields. Name , Age , Address

Using config file want to make Name and Age required.

Later if need want to make Age as optional.

How can we archive that.

Melchia
  • 22,578
  • 22
  • 103
  • 117
SSSS
  • 205
  • 2
  • 8
  • 18

1 Answers1

2

You can install package angular6-json-schema-form by npm i angular6-json-schema-form

Configure form in json format in ts file

exampleJsonObject = {
  "first_name": "Jane", "last_name": "Doe", "age": 25, "is_company": false,
  "address": {
    "street_1": "123 Main St.", "street_2": null,
    "city": "Las Vegas", "state": "NV", "zip_code": "89123"
  },
  "phone_numbers": [
    { "number": "702-123-4567", "type": "cell" },
    { "number": "702-987-6543", "type": "work" }
  ], "notes": ""
};

In HTML

<json-schema-form
  loadExternalAssets="true"
  [(ngModel)]="exampleJsonObject">
</json-schema-form>

More reference at

Package https://www.npmjs.com/package/angular6-json-schema-form

Example https://hamidihamza.com/Angular6-json-schema-form/

Hien Nguyen
  • 24,551
  • 7
  • 52
  • 62