Repeating forms in django form wizard - django

I've created a form wizard in django which starts with a form which the user can enter their details (name, age etc.) into.
The wizard then goes on to some other forms I need.
Now I want to expand the wizard so that the user can add as many other user details as they like.
So basically, it needs to be something like:-
User details -> Do you want to add more?
If yes -> User details
If no -> Next form
I also need the user to be able to edit previous user details or remove previous user details entirely.
I've tried adding a load of conditional forms for the user details, which are switched on or off, depending on whether the user replied Yes to the "add more" question. However, all of the user details form fields have the same name so they overwrite each other. Also, this seems like a hack to me.
So what's the "proper" way to do this? Put simply, how do I conditionally repeat forms based on user input as the wizard progresses?

Then you can use django formsets https://docs.djangoproject.com/en/1.9/topics/forms/formsets/ that way the user can add as many as they like.. However I am not sure how that works with the Wizard thought because of the management form.. You can try it and return feedback :)

Related

django model attribute edit & save with no extra page

I rende certain objects values in django template in a form of a table.
I let user to edit the value and save the edit so I can track the history of edit.
At the moment I use django forms to let user do single object attribute value OR chosen objects attribute values OR all of them and save it.
My problem is with forms is that the way it works at the moment is:
user clicks a value in 'main' page so it links to object 'edit' page in which I return a form so user can edit it.
The problem is with that extra url or extra page. I do not want to do it via separate pages.
I would like to click on the object (like in the excel) and change the value there in 'main' page and submit the edits from the same page.
How can I achieve it with django ?
Can somebody point me into right direction and point out what I should read about to understand it or how I should do it ?
I want to edit either single or let user edit multiple objects values and save the changes and still be able to track the history of edits / changes.
You should look into modals. So when a user clicks to edit it will display a pop-up that you can render the form in without leaving the page.

New to Django. How to incorporate "Add more" button in the form

I'm new to python and the Django framework. I am dealing with lots of forms in my application which is half way developed by the person working in this position earlier. I now need to change the form to incorporate the "Add additional details" button to my existing form.
Can anyone help me out with this? Do let me know in case you need any additional information from my end.
I suggest you read the Forms documentation: https://docs.djangoproject.com/en/dev/topics/forms/?from=olddocs
I don't really understand what you mean by "Add additional details". I'm assuming you want to just add additional items to your form.py of your app, be it model data? Again read the doc's they really helped me.
Is the form using an (inline) formset?
You need to use javascript or jQuery to insert a new set of fields into the web page. The formset management values need to be updated as well.
See this snippet or this plugin

Advanced forms with django-form-builder

So, I've been working with the django-forms-builder library. Now, the use case I'm working on says, that using the admin interface, once creates a form asking for details such as the user's name, email, qualifications and so on. Now, the thing is - a user could have multiple qualifications, so the requirement is to display one field, as well as a small "plus" button - clicking that button displays another field, where you could add a second qualification.
Django-forms-builder does everything else I need it to - but this is the only part where I'm stuck. To make matters worse, I'm not a full-blown Django programmer. Would be grateful for any pointers I could get.
EDIT - To clarify, in my project, one defines the form that will be shown to the end user through the Django admin interface. The form will then be displayed to the end user, and if the end user has any additional qualifications s/he'd would like to add, the form that would be rendered, would have that plus button, to add another field.

Simple dynamic form in Django controlled by the user

I want to make a simple accounting application and I have a model with 3 fields:
account_symbol
account_debit
account_credit
And I want to make a form for the user to enter the accounts for the balance, after entering the first set (of 3 fields) the form (after the user press a button) should reveal another set and so on.
After all the accounts should be entered, the user should submit the form to the database.
I read the b-list.org approach and I don't think is what I need and the formsets docs but what I want is the user to control the length of the form by adding additional sets of 3 fields.
Please point me to an approach for my problem.
Formset is exactly what you need here. You just need to use JavaScript to dynamically show new formsets to user (like in admin app). Here's nice example of doing this.

How to select from a large number of options when completing a form

I am building a web app that allows our field staff to create appointments. This involves creating a record that contains many foreign keys, of which some come from very large tables. For example, the staff will need to select one of potentially thousands of customers.
What's the best way of doing this in Django?
A pop-up box that allows the users to search for customers, gives them the results, the user selects the results, then fills out the main appointment form and then
disappears?
Changing the appointments form to a customer selection page that
then reloads the appointments page with the data in a hidden form? Or
holding the data in some session variables?
Some from of Ajax approach.
A wizard where the flow is: a customer search page, a list of results and they select from results, then a search page for the next option (for example product selection), etc etc
(I'd like to keep it as simple as possible. This is my first Django
project and my first web project for more years than I care to
remember)
ALJ
Imho you should consider some kind of autocomplete fields. I think this results in the best usability for the user. Unfortunately, this always involves Ajax. But if you think that all users have JS turned on this is no problem.
E.g.
django-autocomplete
or what is probably more powerful:
django-ajax-selects
If you do the wizard approach, it will take longer for the user to accomplish the task and makes it harder to change selections.
Edit:
Well with django-ajax-selects you can define how the results should look like. So you can e.g. add the address behind the name.
Quote:
Custom search channels can be written when you need to do a more complex search, check the user's permissions, format the results differently or customize the sort order of the results.
I have done this before by integrating a jQuery autocomplete plugin. But, seeing as this is your first project and your desire to keep it simple, I suppose you could go with the session data option. For instance, you could show a search page where users could search for and select a customer. You could then store the, say, ID of the selected customer object as session data, and use it to pre-populate the corresponding field in the form when displaying the form. That's what I think offhand.