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

160 Views Asked by At

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.

1

There are 1 best solutions below

0
Hien Nguyen On

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/