Use cases -------------- Here we can see some additional things that we can do with the library. Multiple plugins in the same button ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ A button can contain multiple of these functionalities at the same time. For example, a button can be a *confirm* button and a *verify* button at the same time. If using the declarative method, there is a fixed order: #. *verify* #. *confirm* #. *asynctask* #. *showmessage* #. *formset* #. *formbutton* (set the field values that depend on a function) #. the real action (i.e. ``onclick`` handler) E.g. a button that verifies that value of field ``name`` is not empty, and then asks for confirmation before submitting the form: .. code-block:: html .. note:: In this case, the verification happens before the confirmation because of the fixed order. If using the programmatical method, the order in which the actions are added is the order in which they will be executed. E.g. a button can be a *confirm* button and a *verify* button at the same time: .. code-block:: javascript $('#mybutton').powerButtons('confirm', options).powerButtons('showmessage', {showmessage: "The confirmation has been done"}); The button will first show a confirmation dialog, and if it is confirmed, it will show a message dialog, and finally it will continue with its action. Complex workflow ^^^^^^^^^^^^^^^^ Here we can see a full example of a complex workflow that can be done with this library. .. code-block:: html
In this example we have a form. When the user submits it... #. the button verifies that the fields ``name`` and ``email`` are not empty. If they are empty, a modal dialog is shown to the user with the message *please fill all the fields*. #. If the fields are not empty, a confirmation dialog is shown to the user with the message *are you sure you want to submit this form?*. #. If the user confirms, a message dialog is shown to the user with the message *thank you for submitting the form*. #. And finally, the values of the fields ``name`` and ``email`` are set in the hidden field ``payload`` in the form, in JSON format. #. ...and the form is submitted (it was its first purpose). And we did all this without writing a single line of javascript code except for the validation and the creation of the derived values in the payload. Using the library in other than buttons ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ We can use this library in any other clickable component than buttons; e.g. ``a``, ``images``, ``li``, etc. The usage is the same as in buttons, but using the appropriate tag. E.g. will ask for confirmation before following the link: .. code-block:: html follow link E.g. will show a message when the image is clicked: .. code-block:: html