Search code examples
angularjsangular-schema-form

Angular Schema form - Override the input type of a field


Consider the schema

{
  "type": "object",
  "title": "Comment",
  "properties": {
    "name": {
      "title": "Name",
      "type": "string"
    },
    "gender":{
        "title":"Gender",
        "type":"string",
        "enum":["m","f"]
    },
    "comment": {
      "title": "Comment",
      "type": "string",
      "maxLength": 20,
      "validationMessage": "Don't be greedy!"
    }
  },
  "required": [
    "name",
    "email",
    "comment"
  ]
}

How can I override the html form type of gender from select to some another type(like input type text) without using the x-schema-form property and without rewriting the whole fields for the form (using the "*" and just altering the required fields). I tried the following form definition but the field repeats.

[
  "*",
  {
      "key":"gender",
      "type":"text"
  },
  {
    "type": "submit",
    "style": "btn-info",
    "title": "OK"
  }
]

The above definition will show two gender fields, one of type select and other of type text. My requirement is to display only one gender of type text where the gender of type select is displayed.


Solution

  • As of v1.0.0-alpha.1 the ability to use the key "..." has been added to allow adding the remaining undefined schema property keys in the form definition.