PHPackages                             jaxon-php/jaxon-dialogs - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. jaxon-php/jaxon-dialogs

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

jaxon-php/jaxon-dialogs
=======================

Modal, alerts and confirmation dialogs for Jaxon with various javascript libraries

v5.1.3(5mo ago)45.3k36BSD-3-ClausePHPPHP &gt;=8.1CI failing

Since Dec 30Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/jaxon-php/jaxon-dialogs)[ Packagist](https://packagist.org/packages/jaxon-php/jaxon-dialogs)[ Docs](https://github.com/jaxon-php/jaxon-dialogs)[ RSS](/packages/jaxon-php-jaxon-dialogs/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (10)Dependencies (4)Versions (49)Used By (6)

[![Build Status](https://github.com/jaxon-php/jaxon-dialogs/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/jaxon-php/jaxon-dialogs/actions)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/0b7791ebaaee9140a21814c6471d31157dbc7245885e73a7f49f3056db7a75b9/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6a61786f6e2d7068702f6a61786f6e2d6469616c6f67732f6261646765732f7175616c6974792d73636f72652e706e673f623d6d61696e)](https://scrutinizer-ci.com/g/jaxon-php/jaxon-dialogs/?branch=main)[![StyleCI](https://camo.githubusercontent.com/c15a88ffcd28c2fe53dd607d508a5372d6fd20263aa953a2bec2bbf5f55ce34f/68747470733a2f2f7374796c6563692e696f2f7265706f732f36303339303036372f736869656c643f6272616e63683d6d61696e)](https://styleci.io/repos/60390067)[![codecov](https://camo.githubusercontent.com/6d5702a5fdce74cc0f76992ac232070ad755f3ab64aa433e37897b8ad618171a/68747470733a2f2f636f6465636f762e696f2f67682f6a61786f6e2d7068702f6a61786f6e2d6469616c6f67732f6272616e63682f6d61696e2f67726170682f62616467652e7376673f746f6b656e3d4d4b7144566e5737654a)](https://codecov.io/gh/jaxon-php/jaxon-dialogs)

[![Latest Stable Version](https://camo.githubusercontent.com/6e950b6f7f4fba7fe67816846d6e782fe3027eba5ec40de89aa960d88179a46d/68747470733a2f2f706f7365722e707567782e6f72672f6a61786f6e2d7068702f6a61786f6e2d6469616c6f67732f762f737461626c65)](https://packagist.org/packages/jaxon-php/jaxon-dialogs)[![Total Downloads](https://camo.githubusercontent.com/e92985c87dee1c71fdc31f2fb54ec98d8feb7b49362e796e5738079221f973c2/68747470733a2f2f706f7365722e707567782e6f72672f6a61786f6e2d7068702f6a61786f6e2d6469616c6f67732f646f776e6c6f616473)](https://packagist.org/packages/jaxon-php/jaxon-dialogs)[![Latest Unstable Version](https://camo.githubusercontent.com/43bab2fed256163b290b64d40637edce662a8d33b74004c2d822b2b067512ca6/68747470733a2f2f706f7365722e707567782e6f72672f6a61786f6e2d7068702f6a61786f6e2d6469616c6f67732f762f756e737461626c65)](https://packagist.org/packages/jaxon-php/jaxon-dialogs)[![License](https://camo.githubusercontent.com/60cb95110044d54ef1ae0095654140b0ff5ff3dae613ec96f3c35a352f5ea245/68747470733a2f2f706f7365722e707567782e6f72672f6a61786f6e2d7068702f6a61786f6e2d6469616c6f67732f6c6963656e7365)](https://packagist.org/packages/jaxon-php/jaxon-dialogs)

Dialogs for Jaxon
=================

[](#dialogs-for-jaxon)

Modals, alerts and confirmation dialogs for Jaxon with various javascript libraries.

Features
--------

[](#features)

This package provides modal, alert and confirmation dialogs to Jaxon applications with various javascript libraries. 12 libraries are currently supported.

The javascript library to use for each function is chosen by configuration, and the package takes care of loading the library files into the page and generating the javascript code.

The URL and version number can be set individually for each javascript library.

Installation
------------

[](#installation)

Add the following lines in the `composer.json` file, and run the `composer update` command.

```
"require": {
    "jaxon-php/jaxon-core": "^5.3",
    "jaxon-php/jaxon-dialogs": "^5.1"
}
```

Configuration
-------------

[](#configuration)

This package defines 3 config options in the `app.dialogs.default` section to set the default library to be used.

- modal: the default library for modal dialogs
- alert: the default library for alerts
- confirm: the default library for questions

The `app.dialogs.confirm` section defines options for the confirm dialog.

The `app.dialogs.lib.use` option allows to load additional libraries into the page, if they are used in the application.

The `app.dialogs.lib.uri` option defines the URI where to download the libraries files from.

Specific options can also be set for each library.

```
    'dialogs' => [
        'default' => [
            'modal' => 'bootstrap',  // Default library for modal dialogs
            'alert' => 'jconfirm', // Default library for alerts
            'confirm' => 'noty',    // Default library for questions
        ],
        'lib' => [
            'uri' => 'https://cdn.jaxon-php.org/libs',
            'use' => ['cute', 'toastr'], // Additional libraries in use
        ],
        // Confirm options
        'confirm' => [
            'title' => 'Confirm',   // The confirm dialog
            'yes' => 'Oh Yes',       // The text of the Yes button
            'no' => 'No way',        // The text of the No button
        ],
        // Options for the Toastr library
        'toastr' => [
            'options' => [
                'closeButton' => true,
                'positionClass' => 'toast-top-center'
            ],
        ],
        // Load a different version of the JQuery Confirm library from a different CDN
        'jconfirm' => [
            'uri' => 'https://cdnjs.cloudflare.com/ajax/libs',
            'subdir' => 'jquery-confirm',
            'version' => '3.3.2',
        ],
    ],
```

Usage
-----

[](#usage)

### Modal dialogs

[](#modal-dialogs)

This plugin provides functions to show and hide modal dialogs, with a title, a content and zero or more buttons.

```
/**
 * Show a modal dialog.
 */
public function show($title, $content, array $buttons, array $options = []);

/**
 * Hide the modal dialog.
 */
public function hide();
```

The parameters of the `show()` methods are described as follow:

- `$title`: is a one line text to be printed at the top of the dialog.
- `$content`: the HTML content of the dialog.
- `$buttons`: a list of buttons to be printed in the dialog. Each button is an array with the following entries:
    - `title`: the text to be printed in the button.
    - `class`: the CSS class or classes to be applied on the button.
    - `click`: the javascript code to be executed on a click on this button. It can be defined using the [Call Factory](https://www.jaxon-php.org/docs/v5x/ui-features/call-factories.html), or it can be set to `close` to close the dialog.
- `$options`: an array of config options that are specific to the javascript library in use.

Example.

```
    public function showDialog()
    {
        // The dialog buttons
        $buttons = [[
            'title' => 'Close',
            'class' => 'btn',
            'click' => 'close'
        ]];
        // The HTML content of the dialog
        $content = "This modal dialog depends on application settings!!";
        // The dialog specific options
        $options = ['width' => 500];
        // Show the dialog
        $this->response()->dialog->show("Modal Dialog", $content, $buttons, $options);
    }
```

### Alerts or notifications

[](#alerts-or-notifications)

This plugin provides functions to show 4 different types of alerts or notification messages.

```
/**
 * Print a success message.
 */
public function success($message, $title = null);

/**
 * Print an information message.
 */
public function info($message, $title = null);

/**
 * Print a warning message.
 */
public function warning($message, $title = null);

/**
 * Print an error message.
 */
public function error($message, $title = null);
```

Example.

```
    public function save($formValues)
    {
        if(!$this->validator->valid($formValues))
        {
            $this->response()->dialog->title("Error")->error("Invalid input");
            return;
        }
        $this->repository->save($formValues);
        $this->response()->dialog->title("Success")->success("Data saved!");
    }
```

### Confirmation question

[](#confirmation-question)

The `confirm()` function adds a confirmation question to a Jaxon request, which will then be called only if the user answers yes to the given question.

```
/**
 * Add a confirmation question to the request
 */
public function confirm($question, ...);
```

The first parameter, which is mandatory, is the question to ask.

The next parameters are optional; they allow the insertion of content from the web page in the confirmation question, using Jaxon or jQuery selectors and positional placeholders. They are specially useful when pieces of information from the web page need to be inserted in translated strings.

In the example below, the user has to choose a color, and the selected color is inserted in the confirmation question.

Example with Jaxon selector.

```
