Panel dialogs
As part of your Panel area extension, you can also define custom dialogs for the Panel as well as extend or modify the Panel's default dialogs.
Supported UI components
All reuse the same dialog components:
Component name | Usage |
---|---|
k-error-dialog |
For detailed error warnings (i.e. form validation) |
k-form-dialog |
For dialogs with form fields and submit buttons |
k-remove-dialog |
To confirm deleting items |
k-text-dialog |
For dialogs with a custom text message |
More components will be supported in future releases.
Dialog definition
Dialogs are defined as a part of areas:
load
callback
The load
function is called when the dialog is opened. It needs to return an array that specifies the UI component (see above) to be used for the dialog as well as all props that should be passed to the UI component, e.g. field definitions and values for a form dialog.
submit
callback
The submit
function is called once the dialog is submitted and defines the actions triggered by the event byt also the response the Panel will receive.
The dialog's submit
callback has multiple ways to interact with the component presented in the Panel via it's response:
return void
|null
|false
Returning nothing or false
is interpreted as a 404. It suggests that the model could not be found.
return true
Returning true is interpreted as a success and will automatically close the dialog.
return [ ... ]
By returning an array, you gain more control of what happens when the dialog closes. You can pass data to the event, dispatch Vuex events and more.
throw new Exception
Any exception is interpreted as an error and will show the error message box in the dialog containing the exception message
Panel::go()
You can redirect the Panel to a different location after submitting the dialog by calling:
Extending dialogs
We've seen above, how to create entirely new dialogs. But you can also replace or extend the Panel's default core dialogs:
You have multiple options to extend a core dialog: You can keep the submit
handler and only replace the load
setup, you can change both or you can load an entirely new custom dialog component and modify the entire look of the dialog. It's all possible.
Check out the dialog docs above to learn more about dialog setups. It also helps to look at our original source code for dialogs. You can find the dialog code in /kirby/config/areas
. Check out dialog files in the site
, users
and files
subfolders.
Reusing core functionalities
When you plan to extend a dialog, you might want to fall back to Kirby's core behaviour in some cases. This can be done by loading the core code:
Core dialogs
Area | Dialog name |
---|---|
languages |
language.create |
languages |
language.delete |
languages |
language.update |
site |
page.changeSort |
site |
page.changeStatus |
site |
page.changeTemplate |
site |
page.changeTitle |
site |
page.create |
site |
page.delete |
site |
page.duplicate |
site |
page.file.changeName |
site |
page.file.changeSort |
site |
page.file.delete |
site |
site.changeTitle |
site |
site.file.changeName |
site |
site.file.changeSort |
site |
site.file.delete |
users |
user.create |
users |
user.changeEmail |
users |
user.changeLanguage |
users |
user.changeName |
users |
user.changePassword |
users |
user.changeRole |
users |
user.delete |
users |
user.file.changeName |
users |
user.file.changeSort |
users |
user.file.delete |