Django Form so many fields - django

I have a Django page using bootstrap and crispy forms that present a form. but the form is growing so much now that I probably have around 50 fields :( which are all within 1 massive HTML page. I'm pretty sure this is the wrong way to do it.
Is it possible to split the forms into say 5 pages, but still have a submit button to post all of the fields to the database?
For now, what I have done is to create tabs for each section of the giant form so it's easy than scrolling.
I'm thinking it's probably better to create different views for each section and then link the data somehow back using an IndexKey or something?
But i have no idea how i would configure the button to capture all the fields.
I know this is a rubbish question, but I don't really know what to search for?
Cheers

You can try to divide the form in bootstrap tabs like
Personal information --> form fields
Additional information --> form fields

Why don't you break the data input down into as many questions as you think is appropriate for each page? If you have 50 inputs, you could do 10 over 5 pages.
After submitting Page 1, return the POST data to Page 2 and store the data in hidden input fields. Repeat the process until Page 5 when you can POST all 50 to the server and insert the data into your Database.

Related

Using Form Wizard with pages that have no forms

I am working on a Django project where I have about 7 pages all in order. Basically step 1 - 7. I would like for them to have some sort of navigation/progress bar above the content showing where they are in the pages and how much they have completed. The only thing I have found close to this is using Wizard Form. The only issue I run into with this is some pages do not have a form.
Page 1 = Pure text explaining information
Page 2 = Setup information
Page 3 = Form
Page 4 = Form
Page 5 = Information
Page 6 = Form
Page 7 = Completion/Thanks
Is it possible to still use the Wizard Form for this setup? Or is there a better method of doing what I am trying to accomplish?
I haven't used Wizard form, but they look decent. Here are a few things you can try:
The first way is complicated. From my experience, React libraries like Material-UI have support for a navigation bar, progress bar, and all sorts of transition effects. They are complicated to get started though, and I won't advise you to try this unless you had worked with React before.
The second way is sort of a cheat. If Wizard Form requires a form on every single page, you can use something like this to easily get by:
<form method="GET" action="">
<p>Put whatever you want here. Divs, text, whatever.</p>
</form>
As you might've noticed, it's a form with GET request with no actions and a submit button. In that sense, you can just treat this form as a regular division. If Wizard Forms requires just a form, you should get by with this trick.

django - how to make clickable html text that sends data to model?

I want to display users around 10 clickable html "tags" (just text with some css that changes when clicked) on my form page. I want them to be able to select a maximum of 3 tags but no minimum requirement. I then want to take the sum of all clicks for each individual tag and do some calculations with them as a model method, like return the 3 most clicked tags.
It's important that my tags are on the form page and are submitted at the same time as the form. So I guess they have to be part of my form.
How would I go about doing this? An actual example would be tremendously helpful as I'm still very new to django and find the documentation (which I've looked at) somewhat hard to understand.
If you know the tags ahead of time, I'd recommend this setup:
Use a multiple select widget in your form (see the favorite_colors field in this Django widgets example)
Use Select2 or another JavaScript library that converts <select multiple> inputs into a tags-like UI
If you go that route, this widget from django-select2 looks like it should get you off to the races.

Oracle Apex Forms

I have a question about Apex Forms. I have a form with 10 fields, out of which 2 fields are "start_date" and "end_date", I want to ensure that end date must be >= start date, before the page is submitted. But the session state variables don't get user entered values until the page is submitted.
I want a way so that I can access/manipulate fields values before the page is submitted (so to reduce network traffic). Can someone please let me know how I can do it? please help.
Thanks in advance.,
The only way to check the form without submitting it is via Javascript. You could have a button that calls a Javascript function to check the data before submitting the form. See this SO question for some guidance on comparing dates in Javascript.
If you are not experienced with Javascript then this will be quite tricky! Are you sure it is necessary?
You can use validation components for those kind of things: http://docs.oracle.com/cd/E23903_01/doc/doc.41/e21674/bldr_validate.htm

Split form into tabs in Django

I'm developing a Django app which has database driven form fields. I've followed this guide which seems to work so far.
I'm using Twitter Bootstrap and would like to split my fields into tabs. What would be the Django way to do this? Should I append the group label to the id of the form fields and somehow do the magic in the template? Should I use multiple forms in the same view (seems complicated)?
The end result HTML wise is to enclose the input fields in the correct div elements with the group's id like so.
I recently required the very same thing.
After some research, I used django-crispy-forms, which worked quite well. A more detailed instructions about the tabs (and the need of .js file for animation) can be found here, in the 'tabs' section.

Multi-page django form - slider or FormWizard?

I have a long form that I want to break into multiple pages.
I am evaluating between two options for presentation:
Present the form on multiple pages using the FormWizard
Present the form on a slider like CSS3 slider.
The slider is actually just one page long using CSS3 to give impression of slides. It floats all of the content areas next to each other, hides the overflow, sets page width to say 500% if we have 5 slides, and moves the left-margin -100% to show the next slide. So it is all one page but seems like the form is being shown on sliding pages.
To me the advantage of slider approach is that there is only one form and the user submits the form only once at the end of slides and thus can go back and forth to make changes.(This is will be a common case).
Versus having mini-Forms for FormWizard and submitting them after each page. To me, FormWizards seems complicated especially if the user wants to change any of previous page responses. I also need FileField on my form pages and it seems like FormWizard accepts FileField only on the last page.
However, I have not seen many folks use this sliding forms (CSS3 or JScript one) approach. Hence, as a newbie, I am wondering if there are some obvious pitfalls of doing this?
I can only write about FormWizard as I have used it before. According to 'Handling Files' section of Django documentation which can be found in
https://docs.djangoproject.com/en/dev/ref/contrib/formtools/form-wizard/
a FileField can be used in any step of your FormWizard implementation. What I found really helpful by using FormWizard from Django, is that it provides you all the standard functionality of Forms. That means that you can easily create and manipulate forms, validate fields in each step, etc. I am not aware of how CSS3 slider accomplishes validation, but I guess that validation should take place on client side.
Additionally, Django's FormWizard uses either a Cookie storage backend, or a Session storage backend in order to store information, which makes the navigation between steps and modifying previous stored data pretty trivial.
I hope I helped you in your decision! A lot more information can be found of course in the Django documentation of FormWizard in the link I provided above.