Generate pdf in coldfusion with current form inputs - coldfusion

We have a form with a dynamic running totals table beneath the form. For example, when a user changes a value in the Quantity field, the running totals update based on the input (via javascript). The table is displayed only, nothing is saved in the database
We want to be able to generate a pdf that includes the updated running totals. Basically I'm searching if there is some way to pass the current innerHTML within a div to a pdf.
This may have been already asked and answered here- Generate pdf from current document , but the user didn't specifically say that the form updates data after the initial page load. So I just want to be sure I'm not missing something. Thanks. I have a feeling I should look into localStorage for this.

(From the comments)
I think you may be over-complicating the PDF functionality. It is not necessary to keep up with the local changes that the users make as far as generating a PDF is concerned. Most likely the users will make whatever changes to the page and then click a link/button to generate a PDF only after completing all of the changes. At that point you could simply submit a form with all of the updated values to ColdFusion and generate your PDF file. Instead of/or in conjunction with updating the innerHTML of a div, update the hidden form fields as well. Then on the ColdFusion server you could use something like the CFDocument tag to create your PDF from the form fields that were submitted. (Remember to validate all of the form field data before using it.)

Related

Saving ModelForm progress values to session in Django

I have flow where users can create (model) forms. If form is valid, object gets saved and flow continues, but selection is in multiple pages. I need to keep current state of created object, which cannot be saved before it's completely valid.
One thing I can do is to always pass things around those views in the ModelForm to make sure, that user never loses data, but I also wanna make sure, that if he leaves the flow and comes back, he doesn't lose data, that he already entered previously.
That's why I decided I wanna save all the fields to session.
Is this correct approach?
How would you do this?
Where would you put this session logic?
What's best way of getting the fields from incomplete form to be saved?
Edit:
Please don't give me advice on how to use session, I am talking more about high level logic and architecture than specific implementation.
I should describe my flow a bit more. Model has 3 fields.
normal dropdown (foreign key referencing another model)
textfield
another foreign key, but this time not done by select, but it's own separate page with lots of filters to help user pick the right (foreign) model
Flow is not linear, because user can start in different parts of page.
Sometimes user can go to page, where he has first 2 fields + button "Browse", which takes you to selection page for 3rd field. Then after he selects field there, he comes back.
But sometimes he selects first this field and then comes to screen with 2 remaining fields, where he needs to fill those.
django-formtools offers a great way to do this using Form wizard.
The form wizard application splits forms across multiple Web pages. It
maintains state in one of the backends so that the full server-side
processing can be delayed until the submission of the final form.
More info here https://django-formtools.readthedocs.io/en/latest/wizard.html
to save in session:
request.session["variable_name"] = "value"
to get from session request.session["variable_name"]. sure you can use request.session.get("..") in both too

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.

Django/Wagtail - Dynamically generate choices based on uploaded document

I am trying to implement a Chart Block in Wagtail where a user can upload a spreadsheet via the DocumentChooserPanel and then a chart is generated based on the data in that spreadsheet.
I currently have it functioning, but the user must explicitly specify the variable they want the chart to be based off of:
class ChartBlock(blocks.StructBlock):
data_file = DocumentChooserBlock()
primary_variable = blocks.CharBlock(required=True,max_length=255)
class Meta:
template = 'dataviz/blocks/Chart.html'
icon = 'cogs'
label = 'Chart'
I was wondering if there is any way to have the primary_variable field dynamically populated with the column headers from the spreadsheet uploaded and stored in Documents - so that the user would be able to choose from a list of available variables instead of having to remember what a variable was called.
Thank you so much!
This wouldn't be easy to achieve with a vanilla implementation of Wagtail.
The page edit form is generated on page load, including the population of choice lists. I'm pretty sure that the same is true of choice lists in StreamField blocks, that they are populated as the block is added.
The code for this hangs between wagtailadmin.edit_handlers, wagtailadmin.views.pages and wagtailcore.blocks. It would be a pretty complex customisation.
Another possible route for investigation would be using the insert_editor_js hook to update the primary_variable field once a document was uploaded. However, I'm not sure you'll find a dependable ID to hang an event listener off of.
However, you will soon be able to custom validate the submitted page. A PR has just been submitted to allow this custom validation. That should reduce the amount of user error when adding the primary_variable.
This feature should be available in Wagtail 1.4, which I believe is due for release pretty soon.
I hope that helps.

Dynamically Update a Form in Django AFTER Initial Creation/Display

Is there away to dynamically modify and validate a Django form AFTER it's been created and displayed.(I have found a few snippets that show dynamic form creation, but these require that the dynamic fields are known/defined prior to creating the form.) My requirement is different.
Use Case:
I have a form where I want to display and validate additional input fields based on the selection from a dropdown on the initial form. Based on the selection additional fields are 1) added and 2)must then be validated with appropriate error handling.
(In case you are wondering the data elements to be added are a set of name/value pairs stored in csv format in the model, but when displayed they are shown as separate input fields - the input data will be converted to a csv string prior to saving).
I got this partially working using ajax to dynamically add the additional fields to a template, but have not found a way to validate these new fields. I'm not sure if this is a workable approach. I could probably do this in the browser using javascript, but would prefer a Django/server side solution.
OK - So none responded to my question so far. However I did a bit more googling and found an excellent article that describe the solution I was looking for. Major Kudo's to the author of this blog.
Create a Django Dynamic Form with JQuery - Dynamic Field Addition and Removal

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.