Skip to content

Commit

Permalink
fix form submission
Browse files Browse the repository at this point in the history
  • Loading branch information
lekoala committed Aug 2, 2022
1 parent 6d5255e commit 6f97b90
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
1 change: 1 addition & 0 deletions _config/pure-modal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ Name: pure-modal
LeKoala\PureModal\PureModal:
move_modal_to_body: true
overlay_triggers_close: true
compute_iframe_height: false
5 changes: 1 addition & 4 deletions src/PureModal.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* A simple pure css modal for usage in the cms
*
* If your content contains a form, it should be loaded through an iframe
* because you cannot nest forms
* because you cannot nest forms (warning, this gets tricky with "move_modal_to_body")
*
* @author lekoala
*/
Expand Down Expand Up @@ -106,7 +106,6 @@ public static function renderDialog($controller, $customFields = null)
public function setContent($content)
{
$this->content = $content;

return $this;
}

Expand Down Expand Up @@ -160,7 +159,6 @@ public function getTitle()
public function setTitle($title)
{
$this->title = $title;

return $this;
}

Expand All @@ -181,7 +179,6 @@ public function getIframe()
public function setIframe($iframe)
{
$this->iframe = $iframe;

return $this;
}

Expand Down
13 changes: 11 additions & 2 deletions src/PureModalAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,20 @@ public function getOverlayTriggersClose()
return PureModal::getOverlayTriggersCloseConfig();
}

public static function getMoveModalScript()
{
if (!PureModal::config()->move_modal_to_body) {
return '';
}
return "document.getElementById('Form_ItemEditForm').appendChild(this.parentElement.querySelector('.pure-modal'));this.onclick=null;";
}

public function getAttributes()
{
$attrs = [];
// Move modal to body to avoid nesting issues
$attrs['onclick'] = PureModal::getMoveModalScript();
// Move modal to form to avoid nesting issues
// We cannot append to body because this breaks form submission
$attrs['onclick'] = self::getMoveModalScript();
return $attrs;
}

Expand Down
2 changes: 1 addition & 1 deletion templates/LeKoala/PureModal/PureModalAction.ss
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</div>
<% if $ShowDialogButton %>
<div class="toolbar toolbar--south">
<button type="submit" name="action_$Name" class="action custom-action<% if $extraClass %> $extraClass<% end_if %>">
<button type="submit" name="action_$Name" onclick="$SubmitOnClickScript" class="action custom-action<% if $extraClass %> $extraClass<% end_if %>">
{$DialogButtonTitle.RAW}
</button>
</div>
Expand Down

0 comments on commit 6f97b90

Please sign in to comment.