Enable or Disable a Button

Description

Set a button's state to either enabled, or disabled.

images/ed.png

The 'Enable or Disable a Button' action is used with the UX component. The action requires that you specify two properties. These properties specify which button you want to alter the state of and whether that button should be enabled or disabled.

Javascript

For example, the Javascript for disabling a button named BUTTON_1 looks like this:

var btn = {dialog.object}.getControl('BUTTON_1');
btn.setDisabled(true);

To enable the same button the javascript looks like this.

var btn = {dialog.object}.getControl('BUTTON_1');
btn.setDisabled(false);

Enable/Disable Button

Button

Specify the id of the Button to enable or disable.

Mode

Specify if you want to enable or disable the button

Create a Button that Loads an Image

In order to demonstrate whether a button is enabled or disabled, we will first create a button that does something.

  1. In the UX Builder on the UX Controls page open the 'Other Controls' menu. Click on the [Static Text] option.

    images/ed2.png
  2. Highlight the Static Text control in the controls tree. In the properties list on the right set the 'Static text' property to be the following image tag:

    <img id="myid"/>
    images/ed3.png
  3. Open the 'Other Controls' menu and click on [Button] to add a button control to the component.

    images/ed4.png
  4. Highlight the button. In the properties list on the right set the 'Button text' property to read 'Set Image'.

    images/ed5.png
  5. Click the [...] button next to the 'click' property in the 'Javascript - (Touch, Mouse, Pointer Events)' section.

    images/ed6.png
  6. In the Edit Click Event dialog select the 'Action Javascript' radio button and click the 'Add New Action' button.

    images/ed7.png
  7. Type 'image' into the Filter list and select the 'Image Capture - Camera/Photo Library' option. Click OK.

    images/ed8.png
  8. In the Image Capture Properties dialog click the [...] button next to ththe 'Javascript to execute when image has been captured' property.

    images/ed9.png
  9. Add the following code to the onImageCapture definition. Click OK, OK, and Save.

    $('myid').src = e.data;
    images/ed10.png

Create Buttons to Enable or Disable a Button

  1. Open the 'Other Controls' menu and click on the [Button] control option.

    images/ed11.png
  2. Highlight the new button in the controls list. Set the 'Button text' property to read 'Disable'.

    images/ed12.png
  3. In the 'Javascript - (Touch, Mouse, Pointer Events)' section click the [...] button next to the 'click' property.

    images/ed13.png
  4. Select the 'Action Javascript' radio button and click the 'Add New Action' button.

    images/ed7.png
  5. Type 'button' into the 'Filter list'. Highlight the 'Enable or Disable a Button' and click OK.

    images/ed14.png
  6. In the Enable/Disable Button dialog set the 'Button' property to be the button that was defined in the section above, 'BUTTON_1'.

    images/ed15.png
  7. Set the Mode property to 'Disable' and click OK.

    images/ed16.png
  8. Click the [Button] control option in the 'Other Controls' menu again.

    images/ed17.png
  9. Highlight the new button control. Set the 'Button text' property to read 'Enable'.

    images/ed18.png
  10. Click the [...] button next to the 'click' property in the 'Javascript -(Touch, Mouse, Pointer Events)' section.

    images/ed19.png
  11. Select the 'Action Javascript' radio button and click the 'Add New Action' button.

    images/ed7.png
  12. Type 'button' into the 'Filter list', highlight the 'Enable or Disable a Button' action in the action list, and click OK.

    images/ed14.png
  13. In the Enable/Disable Button dialog again set the 'Button' property to be the button defined in the first section, 'BUTTON_1'

    images/ed20.png
  14. Set the 'Mode' property to be 'Enable'. Click OK and Save.

    images/ed21.png
  15. Run the component in Live Preview. Click on the 'Set Image' button. Choose an image to display.

    images/ed22.png
  16. Click the 'Disable' button. The Set Image button should now be disabled preventing you from clicking on it and changing the image.

    images/ed23.png
  17. Click the 'Enable' button. The Set Image button should now be enabled, allowing you to select a new image.

    images/ed24.png

See Also