The Button widget allows the user to execute an action upon clicking it. The type of action executed is determined by the widget settings:

_images/Button-View1.png

Below we will discuss and illustrate the types of actions which may be specified through the Settings wheel as shown in the picture above.

A button can also be shown as inactive, so that it is greyed out and cannot be clicked. See State below.

Note

Please note that calling the pre-defined function ExitAimms from within WebUI (for example, as part of an action behind a button) is currently not supported and will result in an error (for more info on this function, please see AIMMS Function Reference). In fact, calling ExitAimms only works for the main AIMMS thread itself and not for any of the other AIMMS contexts (of which WebUI is just one example). Exiting only from the underlying AIMMS session itself is not deemed to be proper behavior for an application with a WebUI. See also: “Constructs to Avoid” section in the AIMMS PRO documentation.

Action

For example, in the TransNet application, if the action type is set to Procedure, you can select one of the procedures in the model, e.g. SolveProcedure, as the action to be executed:

_images/Button-ActionProcedure.png

If the action type is set to PageLink, you can select one of the other pages in the app’s WebUI to link and open upon click (ResultsStatistics is a potential other page here):

_images/Button-ActionPageLink.png

Finally, if the action type chosen is ExternalLink, you can select a URL for an external web page (i.e. a page not in your WebUI, but from anywhere on the internet) to open:

_images/Button-ActionExternalLink.png

Miscellaneous

In the Miscellaneous tab of the button’s options editor, other options may be set that are explained below:

_images/Button-Misc.png

Title

Set the button title/text here. You can specify either a literal value like “OK” or “Accept” (without the quotes) or a string parameter.

_images/Button_Title.png

Custom Tooltip

You can specify a custom tooltip to display more information when the user hovers over the button. You can specify either a literal value like “Click here to confirm the action” (without the quotes) or a string parameter.

The content for the string parameter can be data driven. It can also contain HTML.

As illustrated below, the definition of string parameter sp_TT_Button is used to specify the Custom Tooltip option.

formatstring("Click to submit the details for <br><br>City: <strong>Amsterdam</strong>");
_images/Button_CustomTooltip.png

State

Starting with WebUI 27.1, you can set a button to an inactive state. An inactive button is greyed out and clicking it does nothing, so the end user can see at a glance which actions are available in the current state of the application.
  • State (optional)
    Sets whether the button is Active (the default) or Inactive.
    The setting can be configured via a literal value (Active or Inactive) or a scalar string parameter.
    The value is not case-sensitive, so inactive and INACTIVE also make the button inactive.
    When the option is left empty, the button is active, the same as in earlier WebUI versions.
    Note: If the string parameter has no value, or a value other than Active or Inactive, the button stays active and a warning is shown in the WebUI messages.
An inactive button still shows its Custom Tooltip when the end user hovers over it, so you can use the tooltip to explain why the action is not available.
_images/button-widget-state-option.png

_images/button-widget-state-inactive.gif

Note

The State option is independent of the Visible option. Use Visible to hide a button and State to make a visible button inactive.
A button can be both hidden and inactive. When it is shown again, it is still inactive.

Styling an inactive button

Inactive buttons use the disabled button colors of the Theming. You can change them with the following variables:
  • --color_bg_button_disabled – the background color

  • --color_text_button_disabled – the text color

  • --border_button_disabled – the border

:root {
    --color_bg_button_disabled: #e0e0e0;
    --color_text_button_disabled: #808080;
    --border_button_disabled: 1px solid #c0c0c0;
}

Preventing repeated clicks during an asynchronous solve

Note

The State option does not by itself stop end users from clicking a button again while the action behind it is still running.
When a procedure starts a solve with pro::DelegateToServer and waitForCompletion := 0, the WebUI stays responsive. An end user who thinks the first click did not go through can click again and start a duplicate solve.
To prevent this, bind the State option to a string parameter and switch it from your model:
  1. Set the string parameter to "Inactive" at the start of the procedure behind the button.

  2. Set it back to "Active" in the completion callback, which runs when the server session has finished.

In the example below, the State option of the button is bound to the string parameter sp_SolveButtonState and its action is the procedure pr_StartSolve:
Procedure pr_StartSolve {
    Body: {
        sp_SolveButtonState := "Inactive";

        if pro::DelegateToServer(waitForCompletion: 0, completionCallback: 'pr_SolveCompleted') then
            return 1;
        endif;

        ! This part runs in the server session
        solve mp_Production;
    }
}

Procedure pr_SolveCompleted {
    Body: {
        sp_SolveButtonState := "Active";
    }
}
Because the button is inactive from the first click until the solve has completed, the end user cannot start a second solve in the meantime.

Visibility

You can control the visibility of the button by either specifying a literal value 1 (visible) or 0 (hidden) or a binary parameter.