提交表单时,我也得到了零值的空字段。我只想接收填写的字段。使用 LR 5.2.3。
提前致谢!阿迪亚
更新(Web 表单的 view.jsp 文件):
<script type="text/javascript">
jQuery(document).ready(
function() {
jQuery('#<portlet:namespace />fm').submit(
function() {
var keys = [];
var fieldLabels = {};
var fieldOptional = {};
var fieldValidationErrorMessages = {};
var fieldValidationFunctions = {};
var fieldsMap = {};
<%
int fieldIndex = 1;
fieldLabel = preferences.getValue("fieldLabel" + fieldIndex, StringPool.BLANK);
while ((fieldIndex == 1) || Validator.isNotNull(fieldLabel)) {
fieldOptional = PrefsParamUtil.getBoolean(preferences, request, "fieldOptional" + fieldIndex, false);
String fieldType = preferences.getValue("fieldType" + fieldIndex, "text");
String fieldValidationScript = preferences.getValue("fieldValidationScript" + fieldIndex, StringPool.BLANK);
String fieldValidationErrorMessage = preferences.getValue("fieldValidationErrorMessage" + fieldIndex, StringPool.BLANK);
%>
var key = "<%= HtmlUtil.escape(fieldLabel) %>";
keys[<%= fieldIndex %>] = key;
fieldLabels[key] = "<%= HtmlUtil.escape(fieldLabel) %>";
fieldValidationErrorMessages[key] = "<%= fieldValidationErrorMessage %>";
function fieldValidationFunction<%= fieldIndex %>(currentFieldValue, fieldsMap) {
<c:choose>
<c:when test='<%= Validator.isNotNull(fieldValidationScript) %>'>
<%= fieldValidationScript %>
</c:when>
<c:otherwise>
jQuery(this).children(':input[value=""]').attr("disabled", "disabled");
return true;
</c:otherwise>
</c:choose>
};
fieldOptional[key] = <%= fieldOptional %>;
fieldValidationFunctions[key] = fieldValidationFunction<%= fieldIndex %>;
<c:choose>
<c:when test='<%= fieldType.equals("radio") %>'>
fieldsMap[key] = jQuery("input[name='<portlet:namespace />field<%= fieldIndex %>']:checked").val();
if (!fieldsMap[key]) {
fieldsMap[key] = '';
}
</c:when>
<c:otherwise>
fieldsMap[key] = jQuery("#<portlet:namespace />field<%= fieldIndex %>")[0].value;
</c:otherwise>
</c:choose>
<%
fieldIndex++;
fieldLabel = preferences.getValue("fieldLabel" + fieldIndex, "");
}
%>
.
.
.
);
}
);
</script>