0

Based on checkbox state i want to enable button if this checkbox is checked and vice versa using thymeleaf with springboot. Here is what i tried :

        <div>
            <label>
            <input type="checkbox" th:value="${test}">
                actif
                </label>
        </div>
        <div>
            <button [disabled]="${test == false}"  type="submit">Envoyer</button>
        </div>
        

In my contoller :

        private boolean test = false;
        model.addAttribute("test", test);
A.Java
  • 39
  • 8
  • If you want this enable/disable to happen dynamically without page refreshes, then you need to use JavaScript. Once your HTML is sent from Thymeleaf to the browser, then Thymeleaf can no longer do work. – Wim Deblauwe Dec 09 '21 at 16:21
  • thanks, i can modify this logic and display error message after submitting my form to avoid what you have said – A.Java Dec 09 '21 at 16:27

1 Answers1

0

As Wim Deblauwe has mentioned, the only way to do that properly is to use JavaScript. For this case it's relatively simple. See this answer for details

Pavel Polyakoff
  • 191
  • 1
  • 13