cguardia / questions

Questions is a form library for Python that uses the power of SurveyJS for the UI.
https://questions.readthedocs.io
MIT License
31 stars 8 forks source link

The survey doesn't contain any visible elements #531

Open ianchov opened 4 weeks ago

ianchov commented 4 weeks ago

Description

I tried your form example from the documentation but apparently the rendered html is invalid as i see only The survey doesn't contain any visible elements.

What I Did

from flask import Flask
from flask import redirect
from flask import request

from questions import Form
from questions import FormPage
from questions import TextQuestion
from questions import DropdownQuestion

class PageOne(Form):
    name = TextQuestion()
    email = TextQuestion(input_type="email", required="True")

class PageTwo(Form):
    country = DropdownQuestion(choices_by_url={"value_name": "name",
        "url": "https://restcountries.eu/rest/v2/all"})
    birthdate = TextQuestion(input_type="date")

class Profile(Form):
    page_one = FormPage(PageOne, title="Identification Information")
    page_two = FormPage(PageTwo, title="Additional Information")

app = Flask(__name__)

@app.route("/", methods=("GET",))
def form():
    form = Profile()
    return form.render_html()

@app.route("/", methods=("POST",))
def post():
    form_data = request.get_json()
    # Here, we would save to a database or something
    print(form_data)
    return redirect("/thanks")

@app.route("/thanks")
def thanks():
    return "Thanks for your information"

if __name__ == "__main__":
    app.run()
nicholasdehnen commented 1 week ago

Running into the same issue with python=3.12, flask=3.0.3 and questions=0.8.0. I assume questions does not work with the latest SurveyJS version?

There is a SURVEY_JS_VERSION = "1.9.81" provided in the settings.py file, but it does not seem to be used and hardcoding that version does not seem to make it work either for me.

Additionally, restcountries.eu is not available anymore and should probably be changed to restcountries.com in the example.

carlosandujar commented 1 week ago

In my case, the "The survey doesn't contain any visible elements" was solved after downgrading pydantic version: pip install pydantic==1.10.11

My config: python=3.9, questions=0.8.0, Flask=3.0.3