🖼️
KASKO Frontend Documentation
  • README
  • Getting started
    • Setting up a new webapp
    • Webapp manifest
    • Building the flow
    • Defining layouts
    • Defining computed values
    • Defining dynamic paths
  • Core concepts
    • Forms
    • Validation
      • Using existing validators
      • Adding custom validators
    • Configuration
      • Price format
      • Date format
    • Performing API calls
    • Toggling visibility of components
    • Translations
    • Rules For Robust Application
  • Guides
    • Using logical statements (JsonLogic)
    • Adding discount codes
    • Developing Custom Plugins
    • Setting required requests
    • Adding save quote for later
    • Transforming request data
    • Manifest merging strategy
    • Knockout flow
    • Local pricing logic
    • Setting up dashboard policy profile
    • Handling offers
    • Repeater
  • Snippets
    • Reset input state
  • Useful resources
    • All component descriptions
    • JsonLogic core documentation
    • Kasko.js documentation
    • Example webapp
    • Example plugins (w/ various frameworks)
Powered by GitBook
On this page
  • Custom operators
  • iso_date
  • length
  • to_object
  • path
  1. Guides

Using logical statements (JsonLogic)

Last updated 1 year ago

In manifest is used for visibility and disabled conditions, for figuring out next screen user needs to be taken and in request data transformers.

interface JsonLogic {
  type: "jsonlogic";
  schema: JsonLogic;
}

JsonLogic can access variables (). Currently these state slices are exposed: input, flags, quote, dataset, context, document, route and query_string.

Custom operators

iso_date

It takes in Date object and returns ISO String of it. If value passed in is not Date object, there will be a warning message and output will be untouched value that was passed in.

This is useful when input has Date object, but some operations have to be made with this value using JsonLogic (e.g. substr to get year, month, day etc.).

Logic
Date
Result

{ "iso_date": {"var":"date"} }

{ date: new Date() }

"2019-06-11"

This operator can also accept modifier value as a second (optional) parameter, that is a string.

Logic
Date
Result

{ "iso_date": [{"var":"date"}, "-5 days"}

{ date: new Date() }

"2019-06-06"

{ "iso_date": [{"var":"date"}, "+1 month"}

{ date: new Date() }

"2019-07-11"

{ "iso_date": [{ "iso_date": [{"var":"date"}, "+2 years"}, "-1 day"}

{ date: new Date() }

"2021-06-10"

length

Returns length of array.

Logic
Input
Result

{ "length": { "var": "input.numbers" }}

{ numbers: ['a', 'b', 'c'] }

3

to_object

Builds object from flat entries list.

Logic
Input
Result

{"to_object": ["foo", 1, "bar", 2]}

...

{"foo": 1, "bar": 2}

path

This is deprecated functionality, please don't use this!

Instead use "cat" operator:

{"var": {"cat": ["input.agents.", {"var": "context.repeater_index"}, ".name"]}}

Has ability to access context from string.

Let's say you have repeater component and in there you must have ability to show/hide field with jsonlogic based on value on particular field in repeater array. We can use path operator in combination with var to do so.

With data:

{
  "agents": [
    {
      "name": "John"
    },
    {
      "name": "Jane"
    },
    {
      "name": "Alfred"
    }
  ]
}
Logic
Context
Result

{"path": "agents.{repeater_index}.name"}

{ repeater_index: 2 }

"agents.2.name"

{"var": {"path": "agents.{repeater_index}.name"}}

{ repeater_index: 2 }

"Alfred"

JsonLogic
more info