Skip to content

Instantly share code, notes, and snippets.

@Super-Chama
Last active May 17, 2022 12:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Super-Chama/9f24b0dfe0d3fa5785bf6d285fbdb9dd to your computer and use it in GitHub Desktop.
Save Super-Chama/9f24b0dfe0d3fa5785bf6d285fbdb9dd to your computer and use it in GitHub Desktop.
// 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"
}
}
},
],
},
},
],
};
// 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