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
Related
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.
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
I am new to Django and tried looking at documentation and a few posts on this forum, but I haven't been able to resolve my problem yet. I'd appreciate any pointers/examples and thanks for your time and help.
I have a working setup for a form with ChoiceField that has 4 choices (CharField). I am trying to include a 5th open option so the User could type their own response. I tried including code for widget, but that made a text box appear below the drop down list. Even with the widget, the validation fails (unless one of the 4 choices is selected) and I have not been able to resolve this problem either.
Is there a solution so the form could accept User inputs within the ChoiceField drop down list?
Best,
Aya
You haven't posted any code, or error message, so I am guessing a bit.
Make sure your form has required=False for the Choice widget. If that is set to True, it will fail the validation.
check out Allow dynamic choice in Django ChoiceField
Optional values will result in an error if you call:
if form.is_valid():
I am working on a django project with complex forms. In one of my form fields I need following functionality...... Its the text field. As the user starts typing the value the suggestions from existing database should appear in dropdown. Can anyone help me out with this ? Just similar to autocomplete but able to add new values.
This is going to be something in the JQuery/AJAX side of things, not Django. I would read up on the autocomplete functions of JQuery and use AJAX to call your DJango code and receive a populated list, which then displays to the user.
JQuery Autocomplete - Custom Data
If you don't want to deal with JavaScript, you can use a django application called django-autocomplete-light.
You can learn more about it (and get it) here: https://github.com/yourlabs/django-autocomplete-light
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.)