How to Programmatically Enable and Disable Buttons


Buttons in a UX component can be enabled and disbled using the button object's setDisabled() method.


Buttons on the UX component are rendered as 'Advanced Buttons'. Advanced buttons are implemented as Javascript objects. In order to enable or disable buttons programmatically, you need to get a pointer to the object and then call the object's setDisabled() method.

All Javascript controls, not just buttons, in the UX control (List, ButtonList, SpinList, Tree, etc.) support the setDisabled() method.

Calling setDisabled on a Button

  1. Get a pointer to the button object from the UX component.

    var bObj = {dialog.object}.getControl('BUTTON_1');
  2. Call the setDisabled() method for the button object.

    //set the button disabled
    //now enable the button

Calling setDisabled() on a Button in a Repeating Section

If the button is in a Repeating Section, you can pass in an optional parameter to the setDisabled() method that specifies what button instance in the repeating section should be enabled or disabled. For example, suppose you have a repeating section with a button called 'BUTTON_2' and you wanted to disable 'BUTTON_2' in the third row of the repeating section. The process for disabling 'BUTTON_2' in the third row is described below:

  1. Get a pointer to the button element in a row in the Repeating Section. The code below demonstrates getting the button element for "BUTTON_2" in the third row of a Repeating Section. To get the button from other rows, replace the "3" in "A5INSTANCE3" with the row number for the row with the button.

    var eles = {dialog.object}.getControl('BUTTON_2_A5INSTANCE3');
  2. Get a pointer to the button object from the UX component. The button in the repeating section is 'BUTTON_2':

    var bObj = {dialog.object}.getControl('BUTTON_2');
  3. Call the setDisabled() method for the button object, passing the eles variable that contains the instance of the button in the repeating section you want to enable ro disable:.


If you omit the optional parameter, all buttons in the Repeating Section will be disabled (or enabled) when you call the setDisabled() method. For example, the code below would disable all instances of 'BUTTON_2' in a repeating section:

var bObj = {dialog.object}.getControl('BUTTON_2');

When working with repeating sections, the row that is visible may not directly reflect the row number for the instance of a control. This is due to the fact that when rows in a repeating section are deleted, they are actually hidden. Once the data for the repeating section is submitted, the control instances will be updated and the hidden "deleted" rows removed.

To get the instance number for the visible row, use the {dialog.object}._repeatingSectionLogicalToPhysicalRow() method. For example:

//Get the Instance Number for the first visible row in RSECTION_1:
var row = {dialog.object}._repeatingSectionLogicalToPhysicalRow('RSECTION_1',1);
In older versions of Alpha Anywhere, a button could either be 'standard' or 'advanced'.

See Also