angular-schema-form icon indicating copy to clipboard operation
angular-schema-form copied to clipboard

x-schema-form should accept all formats for titleMaps

Open donalmurtagh opened this issue 8 years ago • 5 comments

Steps to reproduce

  • Open the Plunker demo
  • Notice that the "Marital status" dropdown contains 3 blank entries
  • If the x-schema-form attributes are removed from the schema and moved to the form definition, it works. In other words, you can workaround the issue by changing the schema to:
    maritalStatus: {
      title: 'Marital status',
      type: 'string',
      'enum': ['married', 'single', 'cohabitating']
    }

and changing the form definition to:

    $scope.form = [{
      key: 'person.details.maritalStatus',
      titleMap: {
        married: 'Married',
        single: 'Single / separated / divorced / widow(er)',
        cohabitating: 'Living with a partner'
      }
    }];

The Plunker demo is using the latest code from the dev branches of angular-schema-form and angular-schema-form-bootstrap.

@json-schema-form/angular-schema-form-lead

donalmurtagh avatar Jun 02 '17 15:06 donalmurtagh

Thanks @donalmurtagh I will be able to make a test out of this to avoid it happening again once fixed, there's so many scenarios that don't have tests still, good to have someone using the framework in a way I don't, I appreciate you taking the time to report them :)

Anthropic avatar Jun 03 '17 14:06 Anthropic

I checked in an old version and the same behaviour exists, the only supported version of titleMap within x-schema-form is an object list like the below:

titleMap: {
  { "value": "married", "name": "Married" },
  { "value": "single", "name": "Single / separated / divorced / widow(er)" },
  { "value": "cohabitating", "name": "Living with a partner" }
}

I can certainly see why it would help if this had of been documented!

It was before my time so the best I can offer is to update the documentation to indicate the requirement for now and keep this issue as an enhancement. I would accept a PR on it, but I can't see myself having the time to fix it given how little time I have unfortunately.

Anthropic avatar Jun 04 '17 12:06 Anthropic

the best I can offer is to update the documentation to indicate the requirement for now and keep this issue as an enhancement

that seems like a reasonable interim measure

donalmurtagh avatar Jun 05 '17 18:06 donalmurtagh

@Anthropic I can confirm that the following successfully works around this issue

'x-schema-form': {
  titleMap: [
    {value: 'married', name: 'Married'},
    {value: 'single', name: 'Single / separated / divorced / widow(er)'},
    {value: 'cohabitating', name: 'Living with a partner'}
  ]
}

Notice that in your code snippet, you proposed assigning an object rather than an array to titleMap, which doesn't work

donalmurtagh avatar Jun 06 '17 09:06 donalmurtagh

Oh sorry, my being lazy I just copied your one from above and altered it to objects for each option and didn't alter the parent brackets :)

Anthropic avatar Jun 06 '17 23:06 Anthropic