Skip to content

Commit

Permalink
LPD-6977 Add name to checkboxNames to allow the checkbox value to be …
Browse files Browse the repository at this point in the history
…submitted

Default browser behavior is to not submit the value of the checkbox when it is unchecked, but we need to always submit the value so the value can be updated in the database.
  • Loading branch information
thektan authored and brianchandotcom committed Mar 21, 2024
1 parent d686b0b commit eadb45b
Showing 1 changed file with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
import com.liferay.portal.kernel.util.Validator;
import com.liferay.taglib.util.TagResourceBundleUtil;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;

Expand All @@ -22,6 +24,13 @@
*/
public class ToggleTag extends BaseContainerTag {

@Override
public int doEndTag() throws JspException {
updateFormCheckboxNames();

return super.doEndTag();
}

@Override
public int doStartTag() throws JspException {
setAttributeNamespace(_ATTRIBUTE_NAMESPACE);
Expand Down Expand Up @@ -314,6 +323,18 @@ else if (Validator.isNotNull(_label)) {
return SKIP_BODY;
}

protected void updateFormCheckboxNames() {
HttpServletRequest httpServletRequest = getRequest();

List<String> checkboxNames =
(List<String>)httpServletRequest.getAttribute(
"LIFERAY_SHARED_aui:form:checkboxNames");

if (checkboxNames != null) {
checkboxNames.add(_name);
}
}

private static final String _ATTRIBUTE_NAMESPACE = "clay:toggle:";

private boolean _disabled;
Expand Down

0 comments on commit eadb45b

Please sign in to comment.