RXNT/react-jsonschema-form-conditionals

Cannot associate an array of events with a condition

donalmurtagh opened this issue · 2 comments

According to the json-rules-engine-simplified docs, it should be possible to specify a list of events for a condition. If I specify a single event, everything works as expected

  const rules = [
    {
      conditions: {
        hasBenefitsReference: {is: true}
      },
      event:
        {
          type: 'require',
          params: {
            field: ['hasBD2Reference', 'BD2Reference']
          }
        }      
    }
  ];

But if I use an array of events instead:

      event: [
        {
          type: 'require',
          params: {
            field: ['hasBD2Reference', 'BD2Reference']
          }
        } 
      ]

I get this error

Warning: Failed props type: Invalid props `rules[0].event` of type `array` supplied to 
`react-jsonschema-form-manager`, expected `object`.

Uncaught ReferenceError: Rule contains invalid action "undefined"
    at toError (utils.js:25)
    at applyRules.js:67
    at Array.map (<anonymous>)
    at applyRules (applyRules.js:59)

I realise it doesn't make much sense to specify an array of events containing just a single event, but the same error occurs when a larger event array is used.

The schema for the example above is:

  const schema = {
    type: 'object',
    properties: {
      hasBenefitsReference: {
        title: 'Do you have a Benefits Reference Number?',
        type: 'boolean'
      },
      benefitsReference: {
        title: 'Benefits Reference Number',
        type: 'string'
      },
      hasBD2Reference: {
        title: 'Do you have a BD2 Number?',
        type: 'boolean'
      },
      BD2Reference: {
        title: "BD2 Number",
        type: 'string',
      }
    }
  };

@mavarazy should I assume from the fact that you've added a test without changing any other code that you were unable to reproduce this issue?

Yes, I've made some changes in the code, the test was added to verify, that it's not related to the Engine. The fix is in eb8e155 - there was an error in validation.

@donalmurtagh - thank you for noticing that, I've released a patched version to npm.