Conditional Rendering

You can use the display attribute to hide/show fields. display will accept either a function or a string and you have access to the field and the model. A string should evaluate true and a function should return true when the field should display.

Asynchronous displays are currently not supported. However there would be ways around this should you need it. Just get creative :)

Using a string expression

{
    key: 'displayMyField',
    type: 'input'
},
{
    key: 'myField',
    type: 'input',
    display: 'model.displayMyField === "yes"'
}

The above example will only display the myField field when the user has written yes in the first field.

Using a function

{
    key: 'displayMyField',
    type: 'input'
},
{
    key: 'myField',
    type: 'input',
    display: function(field, model){
        return model.displayMyField === 'yes';
    }
}

Validation and Conditional Rendering

Sometimes you may require a field to be required or have some sort of validation only when it is displayed. Just go about your validation as normal and Formly will handle the rest.

results matching ""

    No results matching ""