フォームが送信されると、値がゼロの空のフィールドも取得されます。埋められたフィールドだけを受け取りたい。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>