Home > Back-end >  Thymeleaf call a bean on a form field before submit
Thymeleaf call a bean on a form field before submit

Time:07-17

Let us suppose to have a bean:

@Bean
PasswordEncoder getPasswordEncoder()
{
  return new BCryptPasswordEncoder();
}

and on the html page:

 <div >
        <label> Confirm Password</label>
        <input type="password"  th:field="*{confirmPassword}">
    </div> 

Is there any way to call BCryptPasswordEncoder().someFunction() on th:field before its value is send through submit?

CodePudding user response:

Simple answer, No.

Thymeleaf is a rendering engine so it can only do things before the html is served to the end user. If you'd have a need to validate a field before submiting the form you either have to do validation in javascript or have some method to validate in the background against server using ajax.

In most cases normal behaviour would be to do validation on form submit and if it is incorrect give feedback to user than

  • Related