I suggest you to use firefox + firebug extension to see what exactly
your form is sending to server in POST (or GET) request via firebug's
"Console" tab. If data in request is correct every time (change both
selectors, change oly one of them, without changes) -- then problem
somewhere in your django app, otherwise -- check javascript code.

On 15 апр, 21:58, Joakim Hove <joakim.h...@gmail.com> wrote:
> Hello;
>
> I have a problem with a Django using JavaScript which I really don't
> understand. It must be said that this is my first time using
> JavaScript to beef up my forms - that might be source of the problem.
>
> The form presents the user with two drop down selectors and a submit
> button like:
>
>      Country: [------]
>      Product: [------]
>
>      [ Submit ]
>
> Now the available products are not the same in the different
> countries, so when the user has selected a country the browser will
> javscript to ask the server for a list of products available in that
> country. This seems to work, at least the product selection box is
> automatically updated with seemingly correct values. When I am happy
> with both the country and product selection I hit the submit button
> and everything goes to the server running django.
>
> For this particular form I have a clean() method which verifies that
> the chosen product is indeed available in the chosen country (the
> client side javascript should ensure that already, but anyway):
>
>      def clean( self ):
>          product_id = self.cleaned_data.get("product_id")
>          country_id = self.cleaned_data.get("country_id")
>
>          product = Product.objects.get( pk = product_id)        <----
> This fails with Object not found.
>
> As indicated the clean() method fails, and inspection of the DEBUG
> traceback reveals that product_id has the value 'None' - however
> looking at the POST data also present on the DEBUG traceback shows
> that product_id has a reasonable value??? So to me it seems that
> somewhere along the way, the product_id variable is lost?
>
> Some other observations:
> 1. If just dropping the javascrip altogether - i.e. potentially
> allowing for a product/country mismatch the django application works
> as intended.
> 2. If I only change one of the selectors at a time things also work
> nicely. It is possible to select a product "No product" which is
> "available" in all countries and using that it is possible to go
> through the following hoops:
>
>   1) Select product "No product"  [ Submit ]
>   2) Select the country you are interested in [Submit]
>   3) Select the product you are interested in [Submit]
>
> To end up with the desired country and product combination. So - all
> in all I conclude that things can not be totally messed up?
>
> Any tips or thoughts on this would be great!
>
> Joakim

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to