Skip to content

Commit

Permalink
JBPM-10077 Field with LocalDateTime is forcing to enter value even th…
Browse files Browse the repository at this point in the history
…ough its not marked mandatory
  • Loading branch information
bxf12315 committed May 13, 2022
1 parent 0110963 commit a43b96c
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 12 deletions.
Expand Up @@ -160,6 +160,7 @@ public String renderCase(String containerId, CaseDefinition caseDefinition, Form
.append("/instances");

scriptDataList.add(buildFunctionWithBody("getData", "return " + jsonTemplate.toString()));
scriptDataList.add(getLocalDateWithoutTime());
scriptDataList.add(buildFunctionWithBody("getCaseEndpoint", "return '" + caseEndpoint.toString() + "';"));
scriptDataList.add(buildFunctionWithBody("initializeForm", ""));
scriptDataList.add(buildFunctionWithBody("endpointSuffix", "return '" + getEndpointSuffix() + "';"));
Expand All @@ -183,6 +184,33 @@ public String renderCase(String containerId, CaseDefinition caseDefinition, Form
return finalOutput;
}

private String getLocalDateWithoutTime() {
StringBuilder function = new StringBuilder();

function.append("function ")
.append("getLocalDateWithoutTime")
.append("(")
.append("elementId")
.append(") { \n")
.append("console.log( 'document.getElementById ='")
.append(" + document.getElementById(elementId).value ")
.append(");")
.append("if(document.getElementById(")
.append("elementId")
.append(")){\n")
.append("return document.getElementById(")
.append("elementId")
.append(").value ;\n")
.append("}else ")
.append("{\n")
.append("return document.getElementById(")
.append("elementId")
.append(").value + 'T00:00' ;")
.append("\n }")
.append("\n };");

return function.toString();
}

public String renderProcess(String containerId, ProcessDefinition processDesc, FormInstance form) {

Expand Down Expand Up @@ -213,6 +241,7 @@ public String renderProcess(String containerId, ProcessDefinition processDesc, F
.append("/instances");

scriptDataList.add(buildFunctionWithBody("getData", "return " + jsonTemplate.toString()));
scriptDataList.add(getLocalDateWithoutTime());
scriptDataList.add(buildFunctionWithBody("getProcessEndpoint", "return '" + processEndpoint.toString() + "';"));
scriptDataList.add(buildFunctionWithBody("initializeForm", ""));
scriptDataList.add(buildFunctionWithBody("endpointSuffix", "return '" + getEndpointSuffix() + "';"));
Expand Down Expand Up @@ -784,11 +813,9 @@ protected String appendExtractionExpression(String type, String name, String id,
.append("')")
.append(getExtractionValue(jsType));
} else {
jsonTemplate.append("document.getElementById('")
jsonTemplate.append("getLocalDateWithoutTime('")
.append(id)
.append("') ")
.append(getExtractionValue(jsType))
.append(" + 'T00:00'");
.append("') ");
}
} else {
jsonTemplate.append("document.getElementById('")
Expand Down
Expand Up @@ -69,9 +69,9 @@
<strong style="color: red">*</strong>
</#if>
<#if item.showTime >
<input id="${item.id}" name="${item.name}" type="datetime-local" class="form-control" value="${item.value}" ${(item.required)?string('required', '')} pattern="${item.pattern}"/>
<input id="${item.id}" name="${item.name}" type="datetime-local" class="form-control" value="${item.value}" ${(item.required)?string('required', '')} />
<#elseif !item.showTime >
<input id="${item.id}" name="${item.name}" type="date" class="form-control" value="${item.value}" ${(item.required)?string('required', '')} pattern="${item.pattern}"/>
<input id="${item.id}" name="${item.name}" type="date" class="form-control" value="${item.value}" ${(item.required)?string('required', '')} />
</#if>
</div>
<#elseif item.type == "slider">
Expand Down
Expand Up @@ -68,9 +68,9 @@
<strong style="color: red">*</strong>
</#if>
<#if item.showTime >
<input id="${item.id}" name="${item.name}" type="datetime-local" class="form-control" value="${item.value}" ${(item.required)?string('required', '')} pattern="${item.pattern}"/>
<input id="${item.id}" name="${item.name}" type="datetime-local" class="form-control" value="${item.value}" ${(item.required)?string('required', '')} />
<#elseif !item.showTime >
<input id="${item.id}" name="${item.name}" type="date" class="form-control" value="${item.value}" ${(item.required)?string('required', '')} pattern="${item.pattern}"/>
<input id="${item.id}" name="${item.name}" type="date" class="form-control" value="${item.value}" ${(item.required)?string('required', '')} />
</#if>
</div>
<#elseif item.type == "documentCollection">
Expand Down
Expand Up @@ -34,8 +34,8 @@ public void testProcessFormRendererWithDate() {

BootstrapFormRenderer bootstrapFormRenderer = new BootstrapFormRenderer();
String outString = bootstrapFormRenderer.renderProcess("test-containerId", processAssetDesc, form);
assertThat(outString).contains("'dateBirth' : String(document.getElementById('field_1703386699666296E12') .value + 'T00:00')");
assertThat(outString).contains("<input id=\"field_1703386699666296E12\" name=\"dateBirth\" type=\"date\" class=\"form-control\" value=\"\" pattern=\"(\\d+)(-|\\/)(\\d+)(?:-|\\/)(?:(\\d+)\\s+(\\d+):(\\d+)(?::(\\d+))?(?:\\.(\\d+))?)?\"/>");
assertThat(outString).contains("'dateBirth' : String(getLocalDateWithoutTime('field_1703386699666296E12') )");
assertThat(outString).contains("<input id=\"field_1703386699666296E12\" name=\"dateBirth\" type=\"date\" class=\"form-control\" value=\"\" />");
}

@Test
Expand All @@ -49,7 +49,7 @@ public void testProcessFormRendererWithDateTime() {
BootstrapFormRenderer bootstrapFormRenderer = new BootstrapFormRenderer();
String outString = bootstrapFormRenderer.renderProcess("test-containerId", processAssetDesc, form);

assertThat(outString).contains("'dateBirth' : String(document.getElementById('field_1703386699666296E12').value");
assertThat(outString).contains("<input id=\"field_1703386699666296E12\" name=\"dateBirth\" type=\"datetime-local\" class=\"form-control\" value=\"\" pattern=\"(\\d+)(-|\\/)(\\d+)(?:-|\\/)(?:(\\d+)\\s+(\\d+):(\\d+)(?::(\\d+))?(?:\\.(\\d+))?)?\"/>");
assertThat(outString).contains("'dateBirth' : String(document.getElementById('field_1703386699666296E12').value)");
assertThat(outString).contains("<input id=\"field_1703386699666296E12\" name=\"dateBirth\" type=\"datetime-local\" class=\"form-control\" value=\"\" />");
}
}

0 comments on commit a43b96c

Please sign in to comment.