🔎 Verify your current mode with our Interaction.
1. Overview
This interaction triggers a specific mode: Add, Edit, or View. The interaction checks on what mode you’re in and then initialises specific actions accordingly.
2. Example
This example shows a dynamic form interaction that adjusts the form's behaviour based on user selections.
- First, it retrieves the selected values using
C.getValueand stores them in thedepartmentSelectvariable. - Then, it checks if the current mode is
addby usingC.state.meta.mode. If it'sadd, it proceeds with a series of conditional checks and actions. - The actions involve setting specific fields as mandatory or non-mandatory using the
C.setFieldMandatoryfunction.
async function handler(C) {
const actions = [];
const departmentSelect = C.getValue("1662670-department");
if (C.state.meta.mode === "add") {
if (
departmentSelect.includes("1773861") &&
!departmentSelect.includes("1773863") &&
!departmentSelect.includes("1773864")
) {
actions.push(C.setFieldMandatory("1662670-content-item", true));
actions.push(
C.setFieldMandatory("1662670-media-buying-items", false)
);
actions.push(
C.setFieldMandatory("1662670-web-development-items", false)
);
}
// Media Alone
if (
!departmentSelect.includes("1773861") &&
departmentSelect.includes("1773863") &&
!departmentSelect.includes("1773864")
) {
actions.push(C.setFieldMandatory("1662670-content-item", false));
actions.push(
C.setFieldMandatory("1662670-media-buying-items", true)
);
actions.push(
C.setFieldMandatory("1662670-web-development-items", false)
);
}
//Web Alone
if (
!departmentSelect.includes("1773861") &&
!departmentSelect.includes("1773863") &&
departmentSelect.includes("1773864")
) {
actions.push(C.setFieldMandatory("1662670-content-item", false));
actions.push(
C.setFieldMandatory("1662670-media-buying-items", false)
);
actions.push(
C.setFieldMandatory("1662670-web-development-items", true)
);
}
//Content and Media
if (
departmentSelect.includes("1773861") &&
departmentSelect.includes("1773863") &&
!departmentSelect.includes("1773864")
) {
actions.push(C.setFieldMandatory("1662670-content-item", true));
actions.push(
C.setFieldMandatory("1662670-media-buying-items", true)
);
actions.push(
C.setFieldMandatory("1662670-web-development-items", false)
);
actions.push(C.setValue("1662670-web-development-items", []));
}
//Content and web
if (
departmentSelect.includes("1773861") &&
!departmentSelect.includes("1773863") &&
departmentSelect.includes("1773864")
) {
actions.push(C.setFieldMandatory("1662670-content-item", true));
actions.push(
C.setFieldMandatory("1662670-media-buying-items", false)
);
actions.push(C.setValue("1662670-media-buying-items", []));
actions.push(
C.setFieldMandatory("1662670-web-development-items", true)
);
}
//Content, media and web
if (
departmentSelect.includes("1773861") &&
departmentSelect.includes("1773863") &&
departmentSelect.includes("1773864")
) {
actions.push(C.setFieldMandatory("1662670-content-item", true));
actions.push(
C.setFieldMandatory("1662670-media-buying-items", true)
);
actions.push(
C.setFieldMandatory("1662670-web-development-items", true)
);
}
//Media and Web
if (
!departmentSelect.includes("1773861") &&
departmentSelect.includes("1773863") &&
departmentSelect.includes("1773864")
) {
actions.push(C.setFieldMandatory("1662670-content-item", false));
actions.push(C.setValue("1662670-content-item", []));
actions.push(
C.setFieldMandatory("1662670-media-buying-items", true)
);
actions.push(
C.setFieldMandatory("1662670-web-development-items", true)
);
}
if (
!departmentSelect.includes("1773861") &&
!departmentSelect.includes("1773863") &&
!departmentSelect.includes("1773864")
) {
actions.push(C.setFieldMandatory("1662670-content-item", false));
actions.push(
C.setFieldMandatory("1662670-media-buying-items", false)
);
actions.push(
C.setFieldMandatory("1662670-web-development-items", false)
);
actions.push(C.setValue("1662670-content-item", []));
actions.push(C.setValue("1662670-media-buying-items", []));
actions.push(C.setValue("1662670-web-development-items", []));
}
}
return C.mergeAll(actions);
}📌 Need Help?
