angularjsangular-schema-form

Angular schema form + highlight fields with errors on form load


I am using angular schema form. The problem I have is, when I try to load the form there are some required attributes which are missing! The form doesn`t indicate about the missing properties. But when I click on that particular field and edit something and then remove it, it does show highlight the field for me. I want this to happen at initial loading as well. Looking for pointers. Thanks


Solution

  • You need to use required property in your form config schema:

    //..other fields
    "required": [
        "name",
        "email",
        "comment"
      ]
    

    Check the demo here, it has required fields as well:

    {
      "type": "object",
      "title": "Comment",
      "properties": {
        "name":  {
          "title": "Name",
          "type": "string"
        },//here validation details
        "email":  {
          "title": "Email",
          "type": "string",
          "pattern": "^\\S+@\\S+$",
          "description": "Email will be used for evil."
        },
        "comment": {
          "title": "Comment",
          "type": "string",
          "maxLength": 20,
          "validationMessage": "Don't be greedy!"
        }
      },//here naming fields required
      "required": ["name","email","comment"]
    }