Jenkins can display dialogs with a simple-to-use JavaScript API. They serve as replacement for the browser built-in dialogs for alert, prompt and confirm, additionally you can show arbitrary content in a modal or have complete forms in a dialog. As dialogs are executed asynchronously they can't be used as a 1:1 replacements for the browser built-ins.Behaviour
Click on the "X" in the top right or outside to close me.
You can include icons
Dialogs are cool.
Alerts
Replaces the browser built-in alert(message). Contrary to the built-in the code will not wait until the user has closed the alert but as long as the alert is shown the user cant do anything else. Clicking outside the dialog will have no effect, the button must be used to close it.
Alerts are usually used to show error messages.
showAlert()
Prompts
Replaces the browser built-in prompt(message) to query a single value from a user. This returns a promise that allows the script to react when the user has entered the value or aborted. Clicking outside the dialog will have no effect, the buttons must be used to close it. Default minWidth: 400px
showPrompt()
Confirmations
Replaces the browser built-in confirm(message) to make a user confirm an action. This returns a promise that allows the script to react when the user has confirmed or denied. Clicking outside the dialog will have no effect, the buttons must be used to close it. By default, the OK button gets the text Yes
showConfirm()
Modals
Presents a popup to the user with arbitrary information. A modal has no buttons at the bottom. Instead, a close button is added to the upper right corner (can also be hidden). The dialog is closed when clicking outside of it.
showModal()
Forms
Shows a form inside a dialog. For proper functionality, do not wrap the template inside a template
block as scripts that are included by forms are not loaded immediately in that case.
Do not include buttons to submit, apply or cancel the form. Those are added automatically. Adding buttons to validate things or testing connections is fine.
You can either handle the form directly or submit the form.
By default, the OK button gets the text Submit
which is rather generic. Try to use something, that fits the context e.g. Add
. Default minWidth: 600px
showForm()
Customizing the appearance and behaviour
All dialogs take a second optional parameter with options that allow to change certain aspects.message
: Adds a message to the dialogokText
: Adjust the text of the OK button, the default depends on the type of dialogcancelText
: Adjust the text of the Cancel button, defaults toCancel
type
: Change the color of theOK
button. Allowed values:destructive
minWidth
: Set the minimum width of the dialog, the default depends on the type of dialogmaxWidth
: Set the maximum width of the dialog, defaults to475px
hideCloseButton
: Hides the close button in modal dialogs, defaults tofalse
allowEmpty
: When set tofalse
theOK
button will be disabled in the prompt dialog as long as the input field is empty or contains only whitespace, defaults tofalse
submitButton
: Change the behaviour of the submit button in a form dialog. Whentrue
the form will be submitted to theaction
attribute of the form. Whenfalse
, aFormData
object is passed to theresolve
method of thePromise
. Defaults totrue
OK Button texts
There are some predefined button texts available that come with translation. You can refer to them with e.g. dialog.translations.apply
. You can choose from the following texts:
ok
: OKcancel
: Cancelyes
: Yesno
: Noadd
: Addsave
: Saveapply
: Applysubmit
: Submit