Skip to content

feat: allowing x-jsf-logic to affect field attributes #179

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

antoniocapelo
Copy link
Collaborator

This PR aims to allow x-jsf-logic schema to affect properties of fields. From what I can tell, this should be achieved by taking the jsonLogicContext into account when building/mutating the fields. That's the approach I'm following on this WIP PR.

Some examples that should work:

{
  "properties": {
    "amount": {
      "title": "Total amount",
      "type": "number",
      "x-jsf-logic-computedAttrs": {
        "currency": "currency_selected"
      },
      "x-jsf-presentation": {
        "currency": "---",
        "inputType": "money"
      }
    },
    "currency": {
      "oneOf": [
        {
          "const": "AED",
          "title": "AED - United Arab Emirates Dirham"
        },
        {
          "const": "AFN",
          "title": "AFN - Afghanistani Afghani"
        }
      ],
      "title": "Currency",
      "type": "string",
      "x-jsf-presentation": {
        "inputType": "select"
      }
    }
  },
  "title": "Standard Template",
  "type": "object",
  "x-jsf-logic": {
    "computedValues": {
      "currency_selected": {
        "rule": {
          "var": "currency"
        }
      }
    }
  }
}
{
  "properties": {
    "field_a": {
      "type": "number"
    },
    "field_b": {
      "type": "number"
    }
  },
  "x-jsf-logic": {
    "computedValues": {
      "a_plus_ten": {
        "rule": {
          "+": [
            {
              "var": "field_a"
            },
            10
          ]
        }
      }
    },
    "validations": {
      "greater_than_a_plus_ten": {
        "errorMessage": "Must be greater than Field A + 10",
        "rule": {
          ">": [
            {
              "var": "field_b"
            },
            {
              "+": [
                {
                  "var": "field_a"
                },
                10
              ]
            }
          ]
        }
      }
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "field_a": {
            "const": 20
          }
        },
        "required": [
          "field_a"
        ]
      },
      "then": {
        "properties": {
          "field_b": {
            "x-jsf-logic-computedAttrs": {
              "title": "Must be greater than {{a_plus_ten}}."
            },
            "x-jsf-logic-validations": [
              "greater_than_a_plus_ten"
            ]
          }
        }
      }
    }
  ]
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants