4

I'm hoping to use Flask-WTForms to make an input form whose fields change depending on what's in other fields.

For example, say there was a checkbox for "Input Contact". When that was clicked, new fields would appear (or be activated) for putting in a name and number for a contact.

Is that possible using WTForms and Flask? Or do I need to use Javascript?

Thanks a lot, Alex

1 Answer 1

4

It is possible without using Javascript, but it depends on the user experience you want to have.

WTForms only can interact with data that comes in a client-server roundtrip, it doesn't do anything on the browser side on its own. So if after checking the box, a submit happened, then you displayed the contact form, then it's completely plausible to do this without any javascript.

The caveat there is that you have to do a form post, effectively causing the page to refresh and load again. The upside is that this is easy to do in a way that is compatible with all browsers, without dealing with javascript.

The alternative, of course, is to use javascript (or some JS framework like jQuery) to bind actions to happen when that checkbox is checked, causing the other fields to become visible. This is more consistent with user interfaces that people expect in today's applications for such an action, but it does require more work.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.