0

In my app I want to check an input field e.g username if it's exists or not before continue my in form.

I'm using Flask jinja2 for templating. Here is a piece of my code:

 <form method="POST" action="">
   <div class="row">
     <div class="form-group col-lg-9 col-md-9 col-sm-9">
       <label for="inputUsername">User Name</label>
       {{ render_field(form.username, class="form-control rounded" onkeyup="checkUserName()") }}
       </div>

Of course the onkeyup attribut does not work, my question how to perform it ?

Thanks

koul
  • 431
  • 2
  • 10
  • 20
  • Normally, onkeyup kicks off some javascript script. Do you have a javascript function called 'checkUserName' ? – gittert May 06 '19 at 07:28
  • I do have this function on my static/js/main.js – koul May 06 '19 at 08:01
  • 1
    then it would be a good idea to post that script here as well. And the part of your template where js scrips are added to your base template. – gittert May 06 '19 at 08:05
  • After checking other python flask modules, I have found WTForm which have the possibilies to validate data input and has the custom validation which I can just use it in my python code. js here and now is useless. Thanks anyway – koul May 06 '19 at 09:06
  • @koul can you also please look after this issue https://stackoverflow.com/questions/56005424/custom-css-not-working-when-using-bootstrap-with-flask – Himanshu Poddar May 06 '19 at 13:29

1 Answers1

0

Using WTForms for custom validation in my case, it's the good option

koul
  • 431
  • 2
  • 10
  • 20