cancel
Showing results for 
Search instead for 
Did you mean: 

MDK change a control behavior via another control

horiii
Explorer
812

Hello experts,

I need to make an simple property editable/uneditable via a switch. I tried to make a rule at OnPress ( when you press the switch) but does not work. How can I access another control via rule ?

One of my tried was like this:

var controlName = 'ControlName'; var control = mdk.findControlByTypeAndName('SimpleProperty', controlName);
View Entire Topic
bill_froelich
Product and Topic Expert
Product and Topic Expert
0 Kudos

There are a couple of other ways to get the control as well. Here is a sample rule that uses two other methods.

/**
 * Describe this function...
 * @param {IClientAPI} context
 */
export default function ToggleSimplePropEnabled(context) {
    // Can get the reference to the simple property control using either method below
    // It is personal preference as to which one to use

    // Get the simple property control reference by target path
    //let simpleProp = context.evaluateTargetPathForAPI('#Page:-Current/#Control:MySimpleProp');

    // Get the simple property control reference using getControl
    let simpleProp = context.getPageProxy().getControl('FormCellContainer').getControl('MySimpleProp');

    // Set the enabled property of the simple property control based on the value of the switch
    return simpleProp.setEnabled(context.getValue());
}
horiii
Explorer
0 Kudos

I tried like this:

/** 
* Describe this function... 
* @param {IClientAPI} clientAPI 
*/
export default function onSwitchPress(context) { 
    // Add your logic here to determine if the button should become enabled
    let simpleProp = context.getPageProxy().getControl('FormCellContainer').getControl('ReceivedSimpleProperty');
    return simpleProp.setEnabled(context.getValue());
}

But it is not working.Instead of FormCellContainer i tried many option like : SimpleProperty, FormCellSimpleProperty, FormCell etc...
ReceivedSimpleProperty is the name of my SimpleProperty control

bill_froelich
Product and Topic Expert
Product and Topic Expert
0 Kudos

Instead of FormCellContainer you will need to use the name of the container for your page. For example here is where my page defines the container type as FormCellContainer and the _Name property is the value to use in the first getControl.

],
"_Name": "FormCellContainer",
"_Type": "Control.Type.FormCellContainer"
}
horiii
Explorer
0 Kudos

And how can I access control from another page

bill_froelich
Product and Topic Expert
Product and Topic Expert
0 Kudos

You can use evaluateTargetPath or evaluteTargetPathForAPI to access controls on another page.

// Just get the value
let otherPagePropVal = context.evaluateTargetPath('#Page:OtherPageName/#Control:SimpleProp/#Value');

// Get a reference to the control so you can call any methods against that control
let otherPageProp = context.evaluateTargetPath('#Page:OtherPageName/#Control:SimpleProp');
let otherVal = otherPageProp.getValue();