JavaScript in Power Apps for Quick Create Forms

I am only posting this because I will forget later.

My objective was to hide a whole section in a quick create form depending on the selection of a yes/no field.

The JavaScript for a quick create form in Power Apps is a little different than on a normal model-driven app form, but all of the clues are there.

When you pass the form context to the JavaScript function, it’s the same thing as the other forms: get the tab, get the section, get the field, do stuff. There’s only one tab on a quick create form: “tab_1.”

If you look at the sections on a quick create form, the name is like this:

Quick create section properties.

If you didn’t change the names to anything, that is your tab and section names.

Tab name: tab_1
Section names: tab_1_column_1_section_1, tab_1_column_2_section_1, tab_1_column_3_section_1

And here’s the code to show or hide a section in the form.

function showHidePaymentReceived (executionContext) {

//If the donation is in-kind, hide the Payment Received section on the quick create form

formContext = executionContext.getFormContext();

var inKind = formContext.getAttribute("jcma_inkind").getValue();

if (inKind == true) {

//hide the Payment Received section
var tab = formContext.ui.tabs.get("tab_1");
var section = tab.sections.get("tab_1_column_2_section_1");
section.setVisible(false);
}
else {
var tab = formContext.ui.tabs.get("tab_1");
var section = tab.sections.get("tab_1_column_2_section_1");
section.setVisible(true);
}
}

Leave a Comment

Your email address will not be published. Required fields are marked *