Question

I am using WTF flask forms to render elements into my report criteria template. Once the user fills the the form and hits enter a post request is made to the corresponding view and the flask form is validated. If there is a validation error then I need to flash the error and return the report criteria template with fields highlighted with error otherwise I need to display the report results. The issue is if there is a validation error then the template returned from the view needs to be loaded into a <div> which is not same as the <div> in which I needs to display the results. Also how do I force an error from my view.

I have the following ajax call at the moment, but for some reason if validation fails it doesnt do anything, whereas if validation passes and there are results returned from the call then it works fine

function loadReport() {
    $.ajax({
        url: <endpoint>,
        dataType: 'text/html',             
        success: function(data) {
                $("#reportResults_placeholder").html(data);
        },
        error: function (request, status, error) {
            $("#reportCriteria_placeholder").html(data);
        }
    });
}
Was it helpful?

Solution

Try

change

 error: function (request, status, error) {
                $("#reportCriteria_placeholder").html(data); //change data to error
            }

to

 error: function (request, status, error) {
                $("#reportCriteria_placeholder").html(error); //change data to error
            }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top