-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevent modal dismiss in case of form submission errors
- Loading branch information
Showing
7 changed files
with
81 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/main/java/com/xfyre/tapestry5/xtensions/mixins/ModalIntegration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.xfyre.tapestry5.xtensions.mixins; | ||
|
||
import org.apache.tapestry5.MarkupWriter; | ||
import org.apache.tapestry5.annotations.InjectContainer; | ||
import org.apache.tapestry5.annotations.MixinAfter; | ||
import org.apache.tapestry5.corelib.components.Form; | ||
|
||
@MixinAfter | ||
public class ModalIntegration { | ||
@InjectContainer | ||
private Form form; | ||
|
||
void afterRender ( MarkupWriter markupWriter ) { | ||
if ( form.getHasErrors () ) | ||
markupWriter.attributeNS ( null, "data-submission-failed", "true" ); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/com/xfyre/tapestry5/xtensions/services/ModalIntegrationWorker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.xfyre.tapestry5.xtensions.services; | ||
|
||
import org.apache.tapestry5.corelib.components.Form; | ||
import org.apache.tapestry5.model.MutableComponentModel; | ||
import org.apache.tapestry5.plastic.PlasticClass; | ||
import org.apache.tapestry5.services.transform.ComponentClassTransformWorker2; | ||
import org.apache.tapestry5.services.transform.TransformationSupport; | ||
|
||
import com.xfyre.tapestry5.xtensions.mixins.ModalIntegration; | ||
|
||
public class ModalIntegrationWorker implements ComponentClassTransformWorker2 { | ||
@Override | ||
public void transform ( PlasticClass plasticClass, TransformationSupport support, MutableComponentModel model ) { | ||
if ( Form.class.getName ().equals ( plasticClass.getClassName () ) ) | ||
model.addMixinClassName ( ModalIntegration.class.getName () ); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 13 additions & 21 deletions
34
src/main/resources/META-INF/modules/t5xtensions/modaldialog.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,20 @@ | ||
define(["jquery","t5/core/events", "t5/core/zone", "bootstrap/modal"], function($, events, zone) { | ||
return function(spec) { | ||
var $modal = $('#' + spec.id); | ||
|
||
/* | ||
if (spec.width) { | ||
var realWidth = spec.width > $(window).width() ? $(window).width() : spec.width; | ||
$('#' + spec.id + ' > .modal-dialog').width(realWidth); | ||
} | ||
*/ | ||
|
||
var $modal = $('#' + spec.id) | ||
|
||
$modal.on('hidden.bs.modal', function(event) { | ||
$modal.remove(); | ||
|
||
$modal.remove() | ||
if (spec.updateZoneLink) { | ||
var $zone = $('#' + spec.zoneId); | ||
$zone.trigger(events.zone.refresh, {url: spec.updateZoneLink}); | ||
$('#' + spec.updateZone).trigger(events.zone.refresh, {url: spec.updateZoneLink}) | ||
} | ||
}); | ||
}) | ||
|
||
if (spec.monitorZone) | ||
$('#' + spec.monitorZone).on(events.zone.didUpdate, function(event){ | ||
if (spec.hide && !$modal.find('form[data-submission-failed="true"]').length) $modal.modal('hide') | ||
}) | ||
|
||
if (spec.hide && spec.zoneId) { | ||
var $zone = $('#' + spec.zoneId); | ||
$zone.on(events.zone.update, function(){ $modal.modal('hide'); }) | ||
} | ||
$modal.modal() | ||
} | ||
}); | ||
|
||
$modal.modal(); | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters