Skip to content Skip to sidebar Skip to footer

How Access Wtform With Jquery

I would like to ask for help with accessing WTForm fields: I have following form: class model_bolt_InputForm(FlaskForm): # Bolt Inputs bolt_size = SelectFi

Solution 1:

You cannot access form data in your template the way you are trying to. If you are using javascript to get data from the form then. IF you don't specify an ID for your form elements, WTForm will render them using the variable name as the id attribute as well as the name attribute pf the HTML input. You can use that to select that input by id using javascript/jquery Your jquery code should look like this.

<script>

        $(document).ready(function(){

            $('#btn1').click(function(){

                $('.para1').toggle();
                var boltPreloadInput = $('#bolt_preload');
                alert(boldPreloadInput.val());

            });

        });

</script>

When you use WTForms, your form elements render to HTML inputs on page load. Once the page is loaded, you cannot access form data on the client side like you are trying. The only way to interact with the form on click events without first sending the data to the server is by using javascript.

Post a Comment for "How Access Wtform With Jquery"