Skip to content

Support formContext in conditions #74

Description

@timkindberg

I'm trying to make a PR to add support for the formContext in the rule conditions. Here is the new test I've added to your codebase. It's proving to be much more difficult (or rather, hacky) than I expected.

test("FormConditionals - onChange called with corrected schema when formContext changes", () => {
  const changed = sinon.spy(() => {});
  const RULES = [
    {
      conditions: {
        'formContext.foo': "empty",
      },
      event: {
        type: "remove",
        params: {
          field: ["lastName", "name"],
        },
      },
    },
  ];
  const props = { schema, uiSchema: {}, rules: RULES, Engine };
  const formContext = { foo: 1 };
  const wrapper = mount(
    <FormWithConditionals {...props} formData={{ firstName: "A" }} formContext={formContext} onChange={changed} />
  );

  wrapper.setProps({ formContext: { foo: undefined } });

  return new Promise(resolve => setTimeout(resolve, 500)).then(() => {
    const expSchema = {
      type: "object",
      properties: {
        firstName: { type: "string" },
      },
    };

    expect(changed.called).toEqual(true);
    expect(changed.calledOnce).toEqual(true);
    expect(changed.getCall(0).args[0].schema).toEqual(expSchema);
  });
});

Any chance you could give me your high level two cents on how you might implement this and I could cross check it with what I have? I'll open a WIP PR so you can see where I'm currently at.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions