Removing required fields breaks the required array
mrclay opened this issue · 2 comments
mrclay commented
If a required object property is removed via a rule, unrelated property names are removed from the object's required
array:
const rules = [{
event: { type: 'remove', params: { field: 'two' }},
conditions: { not: { one: { equal: true }}},
}];
const schema: JSONSchema4 = {
type: 'object',
properties: {
one: { type: 'boolean', title: '1. Should we show (2)?' },
two: { type: 'string', title: '2. Only shown if (1) is true' },
three: { type: 'string', title: '3. Always shown and required' },
four: { type: 'string', title: '4. Always shown and required' },
},
};
// strips 3 and 4 of required status
schema.required = ['one', 'two', 'three', 'four'];
// works fine
//schema.required = ['one', 'three', 'four', 'two'];
Strangely, placing the conditional field name at the end of the required
list (incompletely) fixes this. If your last field in a property is conditional, there's no way to keep it required.