This is an automated email from the ASF dual-hosted git repository. jleroux pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git
The following commit(s) were added to refs/heads/trunk by this push: new 6bfae12 Improved: Form widget "checkbox" do not persist selected value with multiple options checked (OFBIZ-12154) 6bfae12 is described below commit 6bfae1293a41c8d7ba1780f68678dcf3b8662236 Author: Jacques Le Roux <jacques.le.r...@les7arts.com> AuthorDate: Tue Mar 2 12:09:16 2021 +0100 Improved: Form widget "checkbox" do not persist selected value with multiple options checked (OFBIZ-12154) I tried to use the form-widgets checkbox on a custom find screen. But after searching values with option/s checked, no checkbox remains selected. I found similar kind of ticket OFBIZ-11933. The checkbox was replaced by usage of the asmselect jQuery plugin This fixes the bug at the framework level. jleroux: fixes checkstyle issues: missing spaces after (3) if Thanks: Nameet Jain --- .../ofbiz/widget/renderer/macro/MacroFormRenderer.java | 15 ++++++++++++++- .../common-theme/template/macro/HtmlFormMacroLibrary.ftl | 2 +- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/macro/MacroFormRenderer.java b/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/macro/MacroFormRenderer.java index eca47ff..17c4997 100644 --- a/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/macro/MacroFormRenderer.java +++ b/framework/widget/src/main/java/org/apache/ofbiz/widget/renderer/macro/MacroFormRenderer.java @@ -861,6 +861,16 @@ public final class MacroFormRenderer implements FormStringRenderer { } } String tabindex = modelFormField.getTabindex(); + + List<String> currentValueList = null; + if (UtilValidate.isNotEmpty(currentValue)) { + if (currentValue.startsWith("[")) { + currentValueList = StringUtil.toList(currentValue); + } else { + currentValueList = UtilMisc.toList(currentValue); + } + } + List<ModelFormField.OptionValue> allOptionValues = checkField.getAllOptionValues(context, WidgetWorker.getDelegator(context)); items.append("["); for (ModelFormField.OptionValue optionValue : allOptionValues) { @@ -870,6 +880,9 @@ public final class MacroFormRenderer implements FormStringRenderer { items.append("{'value':'"); items.append(optionValue.getKey()); items.append("', 'description':'" + encode(optionValue.getDescription(), modelFormField, context)); + if (UtilValidate.isNotEmpty(currentValueList) && currentValueList.contains(optionValue.getKey())) { + items.append("', 'checked':'" + Boolean.TRUE); + } items.append("'}"); } items.append("]"); @@ -886,7 +899,7 @@ public final class MacroFormRenderer implements FormStringRenderer { sr.append("\" conditionGroup=\""); sr.append(conditionGroup); sr.append("\" allChecked="); - sr.append((allChecked != null ? Boolean.toString(allChecked) : "\"\"")); + sr.append((allChecked != null && currentValueList == null ? Boolean.toString(allChecked) : "\"\"")); sr.append(" currentValue=\""); sr.append(currentValue); sr.append("\" name=\""); diff --git a/themes/common-theme/template/macro/HtmlFormMacroLibrary.ftl b/themes/common-theme/template/macro/HtmlFormMacroLibrary.ftl index 741871e..22a912e 100644 --- a/themes/common-theme/template/macro/HtmlFormMacroLibrary.ftl +++ b/themes/common-theme/template/macro/HtmlFormMacroLibrary.ftl @@ -197,7 +197,7 @@ under the License. <input type="checkbox"<#if (item_index == 0)> id="${id}"</#if><#rt/><#if tabindex?has_content> tabindex="${tabindex}"</#if><#rt/> <#if disabled?has_content && disabled> disabled="disabled"</#if><#rt/> <#if allChecked?has_content && allChecked> checked="checked" <#elseif allChecked?has_content && !allChecked> - <#elseif currentValue?has_content && currentValue==item.value> checked="checked"</#if> + <#elseif item.checked?has_content && item.checked?boolean> checked="checked"</#if> name="${name?default("")?html}" value="${item.value?default("")?html}"<#if event?has_content> ${event}="${action}"</#if>/><#rt/> ${item.description?default("")} </span>