0

I am having a form and in that checkbox and button is present, on click of button, the data are submitting and also inserting in database, but my page is refreshing, I want my data should submit and insert in database and also page should not refresh in thymeleaf spring boot. The values in checkbox are displaying in loop. My current code is:

<form class="myform myform-newaccount" action="#" id="myForm"
                th:action="@{/authorList?buttonValue=pluginlist}"
                th:object="${userModifyDto}" method="post">
<input type="checkbox" name="applicationId" th:field="*{applicationIds}" id="myCheck" 
th:value="${option.applicationId}" /> 
<input type="submit" value="send" id="myid"/>

</form>
developer_user
  • 463
  • 2
  • 5
  • 13

1 Answers1

0

The default behaviour of server-side rendering technology such as Thymeleaf is that actions always trigger a page refresh. See Form handling with Thymeleaf for more information on that.

That said, there are 2 options:

  1. Use JavaScript (either plain JS or a framework) to do AJAX requests and avoid the page refreshes.
  2. Use hx-boost from the htmx library. This will make it seem like there is no page refresh by intercepting the form submit and doing the request to the server via an AJAX call. See TodoMVC with Thymeleaf and HTMX for more information on that option.
Wim Deblauwe
  • 25,113
  • 20
  • 133
  • 211