Skip to content

Commit 2f925b3

Browse files
committed
Support for non-form slideouts
Resolves #13593 Resolves #17187
1 parent 5c9a1c5 commit 2f925b3

File tree

4 files changed

+31
-22
lines changed

4 files changed

+31
-22
lines changed

CHANGELOG-WIP.md

+1
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@
2626
- Added `craft\web\Request::getValidatedQueryParam()`.
2727
- Added the `buttonGroup` and `buttonGroupField` macros to the `_includes/forms.twig` template.
2828
- Added the `_includes/forms/buttonGroup.twig` template.
29+
- `Craft.CpScreenSlideout` now supports overriding the `closeOnEsc`, `closeOnShadeClick`, `containerElement`, and `containerAttributes` settings. Slideouts with a non-`<form>` container element won’t get a “Save” button, and the close button will be labelled “Close” rather than “Cancel”. ([#13593](https://github.com/craftcms/cms/discussions/13593))

src/web/assets/cp/dist/cp.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/web/assets/cp/dist/cp.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/web/assets/cp/src/js/CpScreenSlideout.js

+28-20
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,20 @@ Craft.CpScreenSlideout = Craft.Slideout.extend(
5555

5656
init: function (action, settings) {
5757
this.action = action;
58-
this.setSettings(settings, Craft.CpScreenSlideout.defaults);
58+
59+
settings = Object.assign({}, Craft.CpScreenSlideout.defaults, settings);
60+
Object.assign(settings.containerAttributes, {
61+
id: `cp-screen-${Math.floor(Math.random() * 100000000)}`,
62+
class: 'cp-screen',
63+
});
64+
const isForm = settings.containerElement === 'form';
65+
if (isForm) {
66+
Object.assign(settings.containerAttributes, {
67+
action: '',
68+
method: 'post',
69+
novalidate: '',
70+
});
71+
}
5972

6073
this.fieldsWithErrors = [];
6174

@@ -124,29 +137,20 @@ Craft.CpScreenSlideout = Craft.Slideout.extend(
124137
this.$cancelBtn = $('<button/>', {
125138
type: 'button',
126139
class: 'btn',
127-
text: Craft.t('app', 'Cancel'),
140+
text: isForm ? Craft.t('app', 'Cancel') : Craft.t('app', 'Close'),
128141
}).appendTo($btnContainer);
129-
this.$saveBtn = Craft.ui
130-
.createSubmitButton({
131-
label: Craft.t('app', 'Save'),
132-
spinner: true,
133-
})
134-
.appendTo($btnContainer);
142+
if (isForm) {
143+
this.$saveBtn = Craft.ui
144+
.createSubmitButton({
145+
label: Craft.t('app', 'Save'),
146+
spinner: true,
147+
})
148+
.appendTo($btnContainer);
149+
}
135150

136151
let $contents = this.$header.add(this.$body).add(this.$footer);
137152

138-
this.base($contents, {
139-
containerElement: 'form',
140-
containerAttributes: {
141-
id: `cp-screen-${Math.floor(Math.random() * 100000000)}`,
142-
action: '',
143-
method: 'post',
144-
novalidate: '',
145-
class: 'cp-screen',
146-
},
147-
closeOnEsc: false,
148-
closeOnShadeClick: false,
149-
});
153+
this.base($contents, settings);
150154

151155
this.$container.data('cpScreen', this);
152156
this.on('beforeClose', () => {
@@ -817,9 +821,13 @@ Craft.CpScreenSlideout = Craft.Slideout.extend(
817821
},
818822
{
819823
defaults: {
824+
containerElement: 'form',
825+
containerAttributes: {},
820826
params: {},
821827
requestOptions: {},
822828
showHeader: null,
829+
closeOnEsc: false,
830+
closeOnShadeClick: false,
823831
closeOnSubmit: true,
824832
onLoad: () => {},
825833
onSubmit: () => {},

0 commit comments

Comments
 (0)