How to select multiple values without hitting control using django forms and the SelectMultiple widget? - django-forms

I need to have a field of my form that allows multiple selections so I went through the Django documentation and found the widget SelectMultiple.
It works but only if I press control while selecting the multiple values otherwise it only keeps the last one clicked which is not ideal...
Are there some parameters that I missed or is there another way to do it?
Thanks.
country_selected = forms.CharField(label='Select a country',
widget=forms.SelectMultiple(choices=COUNTRY_CHOICES))

Related

JSONObject["caption"] not found

We are using form designer of servicenow to change elements on a form.
The table used to create the form is extended by the task table and contains a workflow with approvals and various stages.
When we try to change something within form designer, it does not matter what it is, renaming a field from summary to summarys for instance and clicking save.
The action gives this error:
JSONObject["caption"] not found
Only some forms are affected by this issue, for instance incident forms, change forms all open and can be changed and saved.
I have a feeling that this error is related to a known issue but i just wondered if anyone on here has seen it.
NB: It is not possible to share my JSON response because it's all done behind the scenes by servicenow. I am in a form design view and I am simply clicking save on a form change
Thank you for your time
This has now been resolved.
Turned out a title on a form header had more than 40 characters and this was causing the error on form save.
Max limit on a title

After a form is filled once, I blank out the form before filling it the next time (new conversation), but the borders remain red

I have used webshims for html5 form validation in a single page app with multiple pagelets(divs). The forms are not submitted but local javascript is invoked after each conversation and collected data is posted .
Next I iterate over all the fields and reset the values.
Then I take the new user back to the first pagelet having first form for the new conversation. This time even after filling the correct values the border does not turn green.
Note:
However when we select the field and click outside the field without filling it. and then after filling the correct data border turns green.
However when we tried to achieve it programmatically iterating over each field resetting it and using javascript focus method, that did not do the trick.
I am sure I must be missing some thing. would be able to point out what.
Regards
Barman
I'm not sure, what you want to achieve. I would need to see some code. If you change the value programmatically you can update the validation ui with the event refreshvalidityui on the form field. If you want to reset the ui, you can either trigger a reset event on the form or resetvalidityui on the form field
$('input').val('foo').trigger('refreshvalidityui');
or
$('input').val('foo').trigger('resetvalidityui');
or
$('form').trigger('reset');
Please let me know, if this helps.

Can I create quiz GUI with Django-Forms?

I'm new to django, and I'm working on a quiz project. The idea is to create something similar to this (http://www.stylemint.com/quiz). Basically, there will be a question on each page and the user clicks on an image with the answer. I was planning on using a django form with a radio select input type, however, I'd like the image to act as the radio button (ie, be clickable) and also a click on the image will take you to the next question (instead of having to click submit after each). Is this possible with django, or do I need java?
it's perfectly possible - if you just want a series of images, and clicking on them to take you to the next question you might achieve that by:
Having multiple input fields of type "image" which all submit the form. If you go down that route you'll have to template the forms out yourself or make your own widget.
Using javascript to replace radio buttons with images dynamically. If you do that, it'd be a good idea to make it fall back to a straight list selection for people who don't have javascript.
Ignoring forms altogether and just using a view with a parameter of what the choice is.
Yes, it's completely possible. My suggestion is if you want to save the result in the db use model and model form in django. So, my next suggestion is you can customize model field for combine radio button functionality and image together. But actually you must programming and use a little jquery and javascript to do it.
You may want to see:
https://docs.djangoproject.com/en/dev/topics/forms/modelforms/
https://docs.djangoproject.com/en/dev/howto/custom-model-fields/

FoxPro sum form fields

Using autogenerated form from a single database table. The form uses the class WizBtns included in c:\Program Files\Microsoft Visual FoxPro 9\Wizards. The form has Top, Previous, Next and Bottom buttons.
Although the form only has textboxes to enter data for the fields in the table, I have added a custom Text Box from the toolbox which basically intends to display the sum of some fields. I have bound the ControlSource of the text box to a PUBLIC variable costTotal that is created on the form init.
Now the problem is updating the sum of fields in the text box, or simply updating value of costTotal. Where to add the code for this? Adding the code in the form's Refresh method mixes up the value of costTotal, when I press Next button to update all fields with new values, the custom text box displays the sum of the last record which is mysterious.
I would add a method to the form to do the calculation. Then, call that method from the Valid method of each of the textboxes involved in the calculation.
There is nothing wrong with using the refresh event to recalculate the values, just make sure that you call the refresh each time the record changes
If you are using navigation buttons to move between records then the click event of EACH button is an ideal place to issue the refresh request :-
Assuming the textbox is called txtSum and is located on the same form as the navigation buttons then in each buttons click event add this code
dodefualt()
with thisform
.txtSum.refresh()
endwith
Couple of things:
1) do not use the wizards! Make your own base classes. Trying to figure out what the wizard classes do and how to add functionality will take more time that coding your own base classes. Also, the wizard generated code and classes must be at around 10/20 years old, much has changed since then (a polite way to say they suck).
2) Do not EVER use public variables in FoxPro, except for maybe an app object.
If this is a one shot thing, just add default textboxes and buttons and design the form yourself. You will have total control and you will know what each thing does.

How to handle nested forms in ASP.NET MVC

I'm trying to build a fairly complex form which as a couple of cascading selects - i.e. the user selects a value in one combo and the other combo is populated according to their first selection.
I've followed a tutorial on how to handle the cascading but the problem I have is that I now have nested forms (the code in the tutorial uses forms inside partial views to POST to a controller action to load the 2nd combo). I have my main form on which I want to collect the input values but also the nexted forms for the cascading select boxes. The problem I have is that the cascading selection doesn't post to the correct controller action, but instead posts to my main (outer) form's action.
I understand this is the correct behaviour for a browser (as nested forms apparently aren't supported) but what's the correct way to implement this?
The correct way is to only have one form. Then use AJAX to populate the cascading drop down list. The are 100s of examples online how to do this with JSON
use this to have multiple submit buttons on one form which each have different controller actions to post to:
http://iwayneo.blogspot.co.uk/2013/10/aspnet-mvc-action-selector-with-list.html
as for cascading stuff - i would focus on populating these without Ajax 1st - then you can worry about adding this sort of flare - if it doesn't work without JS anyway you're in a bad place.
I would have the 1st dropdown populated when you initially load the form and have a "next" button to populate the next dropdown in the cascade. this submit can use the method above to post to an action which then populates the second data set based on the selection of the 1st dropdown.
make sense?
Then how you ajax that after the point is up to you but you'll have a very solid foundation to build up stuff like that as you will have it working in the minimal tech scenario.
w://

Resources