3

I want to build a (section of a) form which produces the following output:

{
  ...
  offers: {
     context: "http://schema.org",
     minPrice: 3
  }
  ...
}

The catch is, context should always be present - the only field the user gets to manipulate is minPrice. Immediately, a hidden field with a value comes to mind. So here's the schema definition:

$scope.schema = {
  ...
  offers: {
    type: 'object',
    properties: {
      minPrice: {
        type: 'number'
      }
    }
  }
  ...
};

And here the form definition:

$scope.form = [
  ...
  {
    key: 'offers',
    type: 'fieldset',
    items: [
      {
        key: 'offers.minPrice',
        type: 'number'
      },
      {
        key: 'offers.context',
        type: 'hidden',
        default: 'http://schema.org'
      }
    ]
  }
  ...
];

However, observing the generated model it's obvious the entry context is not present. I have successfully used a combination of type: 'hidden' and default with a tabarray, but I just can't get it right with an object. I am using version 0.8.13 of angular-schema-forms - the latest at the time of this writing.

I'd appreciate any insights, thanks.

Carlos Romero
  • 698
  • 8
  • 18

1 Answers1

0

You must include context and it's default value within the schema in that version.

I expect that your issue relates to a bug which should have been fixed in the alphas for v1.0.0

It should work with:

Schema

{
  "type": "object",
  "properties": {
    "offers": {
      "type": "object",
      "properties": {
        "minPrice": {
          "type": "number"
        },
        "context": {
          "type": "string",
          "default": "http://schema.org"
        }
      }
    }
  }
}

Form

[
  {
    "type": "fieldset",
    "items": [
      {
        "key": "offers.minPrice",
        "type":"number"
      },
      {
        "key": "offers.context",
        "type": "hidden",
        "notitle": true
      }
    ]
  }
]
Anthropic
  • 681
  • 1
  • 11
  • 29