0

On html form with input type="number" that submit decimal numbers the decimal separator (regardless of whether I use a comma or period) is being ignored. To get the correct value I need change my input field to type="text".

Sample: when I submit the value "0.01" in the form it is converted to "1".

HTML form:

<form method="post" class="form-vertical  js-form-loading" th:action="@{/balanco/salvar}" th:object="${medicaoUsina}">
...
<input id="vlAberturaComporta" type="number" min="0" max="11" step="0.01" class="form-control" th:field="*{vlAberturaComporta}" />

Spring controller:

@PostMapping("/salvar")
public ModelAndView salvar(@Valid @ModelAttribute("medicaoUsina") MedicaoUsinaDTO medicaoUsina, BindingResult bindingResult) throws SistemaException {
...

Java DTO MedicaoUsinaDTO:

public class MedicaoUsinaDTO {
    private Long idMedicao;
    private Integer idUsina;
    private BigDecimal vlGeracaoUG1;
    private BigDecimal vlGeracaoUG2;
    private BigDecimal vlGeracaoUG3;
    private BigDecimal vlAberturaComporta;
    ...
}

Using Spring 4.3.23 and Thymeleaf 3.0.2.

I could use input type="text" but I'd prefer to use type="number" so I can use the HTML5 fields validator features.

tgallei
  • 759
  • 2
  • 10
  • 19
danieltc07
  • 108
  • 2
  • 12

0 Answers0