I have a thymeleaf form with file field and checkbox. Both are required
<form action="#" th:action="@{/upload}"
th:object="${data}" method="post" enctype="multipart/form-data">
<input type="file" th:field="*{exampleFile}" accept="application/pdf"/>
<div class="error" (...) />
<input type="checkbox" th:field="*{isOwner}"/>
<div class="error" (...) />
(...)
</form>
and post method
@PostMapping("upload")
public String upload(@Valid @ModelAttribute("data") DataDTO data, BindingResult result, Model model) {
if (result.hasErrors()) {
return "upload";
}
(...)
return "redirect:/confirm";
}
When I select a file but don't check a checkbox and submit a form then I have validation error on checkbox.
there is no validation error on file file (it'a correct) but this field is empty and I need to select file again.
I need the form not to delete the file during validation