Check Current Mode

🔎 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.

  1. First, it retrieves the selected values using C.getValue and stores them in the departmentSelect variable.
  2. Then, it checks if the current mode is add by using C.state.meta.mode. If it's add, it proceeds with a series of conditional checks and actions.
  3. The actions involve setting specific fields as mandatory or non-mandatory using the C.setFieldMandatory function.
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?

If you require assistance or encounter any issues, please don't hesitate to contact us for further support.