json-schema-form / angular-schema-form

Generate forms from a JSON schema, with AngularJS!
https://json-schema-form.github.io/angular-schema-form
MIT License
2.47k stars 653 forks source link

x-schema-form should accept all formats for titleMaps #889

Open donalmurtagh opened 7 years ago

donalmurtagh commented 7 years ago

Steps to reproduce

    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

Anthropic commented 7 years ago

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 commented 7 years ago

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.

donalmurtagh commented 7 years ago

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 commented 7 years ago

@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

Anthropic commented 7 years ago

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 :)