Code Monkey home page Code Monkey logo

mfx-advanced-condition-matcher's Introduction

Advanced expression matcher

mf-dynamic-form plugin

Usage

Use it in your dynamic-form spec in visibleWhen, requiredWhen, disabledWhen

Example:

   new TextboxFormControl({
    key: 'field1',
    label: 'Field 1'
}),
    new TextboxFormControl({
        key: 'field2',
        label: 'Field 2',
        visibleWhen: [new AdvancedConditionMatcher("'$field1' > 5")],
        requiredWhen: [new AdvancedConditionMatcher("'$field1' == 5")]
    }),
    new TextboxFormControl({
        key: 'field3',
        label: 'Field 3',
        disabledWhen: [new AdvancedConditionMatcher(`startsWith($field2, 'Hello') or ($field2 != 'Hi' and $field1 in [10, 20])`)]
    })

Example with external FormGroup:

    externalFormGroup = new FormGroup({
        firstName: new FormControl('Ahmed')
    });


    new TextboxFormControl({
        key: 'field3',
        label: 'Field 3',
        disabledWhen: [new AdvancedConditionMatcher(`startsWith($firstName, 'Ah')`, externalFormGroup)]
    })
            

Expressions

The expression language is based on https://www.npmjs.com/package/expr-eval

Expression Syntax

Is a logical expression, that evaluates to either “true” or “false.

Comparisons Description
x == y Equals
x != y Does not equal
x < y Less than
x <= y Less than or equal to
x > y Greater than
x >= y Greater than or equal to
x in [a, b, c] Equivalent to (x == a or x == b or x == c)
x not in (a, b, c) Equivalent to (x != a and x != b and x != c)
startsWith(x, a) x start with a
endsWith(y, a) x ends with a
contains(x, a) x contains a
notContains(x, a) x not contains a
isNotEmpty(x) x is not empty
isEmpty(x) x is empty
Boolean logic Description
x or y Boolean or
x and y Boolean and
not x Boolean not
( x ) Explicity operator precedence

@Since [email protected]

mfx-advanced-condition-matcher's People

Contributors

hmeyde avatar moolsbytheway avatar zeinebu avatar

Watchers

 avatar  avatar

Forkers

hmeyde

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.