This is an automated email from the ASF dual-hosted git repository. mleila 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 af1a19596d Fixed: Form html validation not working correctly inside a modal (OFBIZ-12825) af1a19596d is described below commit af1a19596d704776d8cec3bd9cc66c3a94e9ab47 Author: MLeila <mle...@apache.org> AuthorDate: Thu May 25 17:49:15 2023 +0200 Fixed: Form html validation not working correctly inside a modal (OFBIZ-12825) Fix form html validation on submit inside a modal to avoid service call when required fields are empty --- .../template/macro/HtmlFormMacroLibrary.ftl | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/themes/common-theme/template/macro/HtmlFormMacroLibrary.ftl b/themes/common-theme/template/macro/HtmlFormMacroLibrary.ftl index fba47ab0e5..a0d4bde2c5 100644 --- a/themes/common-theme/template/macro/HtmlFormMacroLibrary.ftl +++ b/themes/common-theme/template/macro/HtmlFormMacroLibrary.ftl @@ -236,19 +236,27 @@ under the License. <#if title?has_content> alt="${title}"</#if><#if event?has_content> ${event}="${action}"</#if> <#if confirmation?has_content>onclick="return confirm('${confirmation?js_string}');"</#if>/> <#else> - <input type="<#if containerId?has_content>button<#else>submit</#if>" <@renderClass className alert /> <@renderDisabled disabled /> + <input type="submit" <@renderClass className alert /> <@renderDisabled disabled /> <#if id?has_content> id="${id}"</#if><#rt/> <#if name??> name="${name}"</#if> <#if title?has_content> value="${title}"</#if> <#if event?has_content> ${event}="${action}"</#if> - <#if containerId?has_content> onclick="<#if confirmation?has_content>if (confirm('${confirmation?js_string}')) </#if>ajaxSubmitFormUpdateAreas('${formName}', '${ajaxUrl}')" - <#else><#if confirmation?has_content> onclick="return confirm('${confirmation?js_string}');"</#if> - <#if tabindex?has_content> tabindex="${tabindex}"</#if><#rt/> + <#if !containerId?has_content> + <#if confirmation?has_content> onclick="return confirm('${confirmation?js_string}');"</#if> + <#if tabindex?has_content> tabindex="${tabindex}"</#if><#rt/> </#if>/> <#if containerId?has_content> <#-- the form will be submit by ajax, we inform that perss enter need to call --> <script> - $("form[name='${formName}']").keypress(function(e) { + $("form[name='${formName}']") + .submit(function(e) { + e.preventDefault(); + e.stopPropagation(); + if ($(this).valid()) { + <#if confirmation?has_content>if (confirm('${confirmation?js_string}')) </#if>ajaxSubmitFormUpdateAreas('${formName}', '${ajaxUrl}'); + } + }) + .keypress(function(e) { if (e.which === 13 && ! $(e.target).is('textarea')) { e.preventDefault(); $("#${id!}").click();