Generate bracketless tag id in FreeMarker forms

Before this change if FreeMarker Spring form macro was bound to a path
which contains square brackets, those brackets would also appear in id
of generated tag, making the id invalid.

As of this fix all FreeMarker Spring form macros generate tag with id
that does not contain square brackets.

Issue: SPR-8732
This commit is contained in:
Stevo Slavic
2012-03-04 22:02:38 +01:00
parent 9c8332a6c4
commit a9f4206151
3 changed files with 15 additions and 7 deletions

View File

@@ -157,7 +157,7 @@
-->
<#macro formInput path attributes="" fieldType="text">
<@bind path/>
<input type="${fieldType}" id="${status.expression}" name="${status.expression}" value="<#if fieldType!="password">${stringStatusValue}</#if>" ${attributes}<@closeTag/>
<input type="${fieldType}" id="${status.expression?replace('[','')?replace(']','')}" name="${status.expression}" value="<#if fieldType!="password">${stringStatusValue}</#if>" ${attributes}<@closeTag/>
</#macro>
<#--
@@ -202,7 +202,7 @@
-->
<#macro formTextarea path attributes="">
<@bind path/>
<textarea id="${status.expression}" name="${status.expression}" ${attributes}>${stringStatusValue}</textarea>
<textarea id="${status.expression?replace('[','')?replace(']','')}" name="${status.expression}" ${attributes}>${stringStatusValue}</textarea>
</#macro>
<#--
@@ -218,7 +218,7 @@
-->
<#macro formSingleSelect path options attributes="">
<@bind path/>
<select id="${status.expression}" name="${status.expression}" ${attributes}>
<select id="${status.expression?replace('[','')?replace(']','')}" name="${status.expression}" ${attributes}>
<#if options?is_hash>
<#list options?keys as value>
<option value="${value?html}"<@checkSelected value/>>${options[value]?html}</option>
@@ -244,7 +244,7 @@
-->
<#macro formMultiSelect path options attributes="">
<@bind path/>
<select multiple="multiple" id="${status.expression}" name="${status.expression}" ${attributes}>
<select multiple="multiple" id="${status.expression?replace('[','')?replace(']','')}" name="${status.expression}" ${attributes}>
<#list options?keys as value>
<#assign isSelected = contains(status.actualValue?default([""]), value)>
<option value="${value?html}"<#if isSelected> selected="selected"</#if>>${options[value]?html}</option>
@@ -267,7 +267,7 @@
<#macro formRadioButtons path options separator attributes="">
<@bind path/>
<#list options?keys as value>
<#assign id="${status.expression}${value_index}">
<#assign id="${status.expression?replace('[','')?replace(']','')}${value_index}">
<input type="radio" id="${id}" name="${status.expression}" value="${value?html}"<#if stringStatusValue == value> checked="checked"</#if> ${attributes}<@closeTag/>
<label for="${id}">${options[value]?html}</label>${separator}
</#list>
@@ -288,7 +288,7 @@
<#macro formCheckboxes path options separator attributes="">
<@bind path/>
<#list options?keys as value>
<#assign id="${status.expression}${value_index}">
<#assign id="${status.expression?replace('[','')?replace(']','')}${value_index}">
<#assign isSelected = contains(status.actualValue?default([""]), value)>
<input type="checkbox" id="${id}" name="${status.expression}" value="${value?html}"<#if isSelected> checked="checked"</#if> ${attributes}<@closeTag/>
<label for="${id}">${options[value]?html}</label>${separator}
@@ -307,7 +307,7 @@
-->
<#macro formCheckbox path attributes="">
<@bind path />
<#assign id="${status.expression}">
<#assign id="${status.expression?replace('[','')?replace(']','')}">
<#assign isSelected = status.value?? && status.value?string=="true">
<input type="hidden" name="_${id}" value="on"/>
<input type="checkbox" id="${id}" name="${id}"<#if isSelected> checked="checked"</#if> ${attributes}/>