Last active
May 17, 2022 12:33
-
-
Save Super-Chama/9f24b0dfe0d3fa5785bf6d285fbdb9dd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Based on a field value, show some extra input fields | |
const schemaOne = { | |
layout: [ | |
{ | |
type: 'grid', | |
props: { | |
cols: 2, | |
}, | |
children: { | |
default: [ | |
{ | |
name: 'firstName', | |
label: 'First Name', | |
type: 'input', | |
}, | |
{ | |
name: 'lastName', | |
label: 'Last Name', | |
type: 'input', | |
//if visible not defined explicitly its true | |
visible: false, | |
// field = field schema of this field | |
// model = model of entire form | |
hook: function(field, model) { | |
return { | |
...field, | |
//visible will be true if firstname is tom | |
visible: model.firstName === "tom" | |
} | |
} | |
}, | |
], | |
}, | |
}, | |
], | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Based on a field value, change the label of another field and disable another field. | |
const schemaTwo = { | |
layout: [ | |
{ | |
type: "grid", | |
props: { | |
cols: 2, | |
}, | |
children: { | |
default: [ | |
{ | |
name: "firstName", | |
label: "First Name", | |
type: "input", | |
}, | |
{ | |
name: "lastName", | |
label: "Last Name", | |
type: "input", | |
// field = field schema of this field | |
// model = model of entire form | |
hook: function (field, model) { | |
return { | |
...field, | |
//label will change to middle name if first name is tom, else keep last name | |
label: model.firstName === "tom" ? "Middle Name" : field.label, | |
//field will be disabled if first name is ben | |
...(model.firstName === "ben" && { props: { disabled: true } }), | |
}; | |
}, | |
}, | |
], | |
}, | |
}, | |
], | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment