Skip to content

Commit

Permalink
Fix#11814: 14.0.1 Support DefaultCommand for submit button outside (b…
Browse files Browse the repository at this point in the history
…ut linked to) form (primefaces#11978)
  • Loading branch information
melloware committed May 22, 2024
1 parent b194707 commit 26f676b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ protected void encodeMarkup(FacesContext context, CommandButton button) throws I
String type = button.getType();
boolean pushButton = ("reset".equals(type) || "button".equals(type));
Object value = button.getValue();
String form = button.getForm();
String icon = button.getIcon();
String title = button.getTitle();
String onclick = null;
Expand Down Expand Up @@ -118,6 +119,10 @@ protected void encodeMarkup(FacesContext context, CommandButton button) throws I
"data-pf-validateclient-update");
}

if (!isValueBlank(form)) {
writer.writeAttribute("data-pf-form", form, null);
}

//icon
if (!isValueBlank(icon)) {
String defaultIconClass = button.getIconPos().equals("left") ? HTML.BUTTON_LEFT_ICON_CLASS : HTML.BUTTON_RIGHT_ICON_CLASS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ protected void encodeMarkup(FacesContext context, CommandLink link) throws IOExc
ResponseWriter writer = context.getResponseWriter();
String clientId = link.getClientId(context);
Object label = link.getValue();
String form = link.getForm();

String request;
boolean ajax = link.isAjax();
Expand Down Expand Up @@ -101,16 +102,20 @@ protected void encodeMarkup(FacesContext context, CommandLink link) throws IOExc
writer.writeAttribute("tabindex", "-1", null);
}

if (!isValueBlank(form)) {
writer.writeAttribute("data-pf-form", form, null);
}

if (ajax) {
request = buildAjaxRequest(context, link);
}
else {
UIForm form = ComponentTraversalUtils.closestForm(link);
if (form == null) {
UIForm uiForm = ComponentTraversalUtils.closestForm(link);
if (uiForm == null) {
throw new FacesException("Commandlink \"" + clientId + "\" must be inside a form component");
}

request = buildNonAjaxRequest(context, link, form, clientId, true);
request = buildNonAjaxRequest(context, link, uiForm, clientId, true);
}

if (csvEnabled) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ PrimeFaces.widget.DefaultCommand = PrimeFaces.widget.BaseWidget.extend({
}

// attach keypress listener to parent form
var closestForm = this.jqTarget.closest('form');
var closestForm = this.jqTarget[0].hasAttribute('data-pf-form')
? $(PrimeFaces.escapeClientId(this.jqTarget[0].getAttribute('data-pf-form')))
: this.jqTarget.closest('form');
var scopeKeydown = 'keydown.' + this.id;
closestForm.off(scopeKeydown).on(scopeKeydown, { scopeEnter: false }, function(e, data) {
if (e.key !== 'Enter') {
Expand Down

0 comments on commit 26f676b

Please sign in to comment.