Errata, this email has correct sources, sorry for the pollution.

On Sun, Dec 21, 2008 at 4:46 PM, Mirat Can Bayrak
<miratcanbay...@gmail.com> wrote:
>
> hi, i have a state selection which has options "exists", "not exists" and 
> "redirected" when it is selected as exists i want to show some more fields, 
> but on other selections i dont want him to show them. can i do that it django?

AFAIK not OOTB. I hope for you that someone is going to post a more
comprehensive reply than this one.

It's hopefully pretty easy to "predict" how django will generate it's
input field, label and fieldset ids in the HTML result. Use your
favorite javascript framework to deal with it:
- attach an event onChange on a field,
- show/hide fields you want when the field's value match something you expected.

I had to create some javascript function to help me (models with
hundred of fields, dozens of conditions), drawbacks are: no
documentation, requires jquery. Reading it might help making your
application specific functions development /slightly/ faster.

function show_field(name)
{
   id = 'id_' + name
   $('.' + name).show();
   $('#' + id).show();
   $('label[for=' + id + ']').show();
}

function hide_field(name)
{
   id = 'id_' + name
   $('.' + name).hide();
   $('#' + id).hide();
   $('label[for=' + id + ']').hide();
}
// geodjango
function show_map(name)
{
   show_field(name);
   $('#' + id).hide();
   $('#id_' + name + '_admin_map').show();
}

function hide_map(name)
{
   $('#id_' + name + '_admin_map').hide();
   hide_field(name);
}

Because of the lack of documentation, this is an example usage which
you'll unfortunnately have to reverse engineer, i've tryed to cut out
everything you don't need and "unfactorized it" to make it "easier" to
understand:

foo_specific_fields = new Array(
   'droits',
   // [...],
   // that's actually a list of field name as they are in your models sources
   'loi_defisc',
);

$(document).ready(function() {
   $('#id_foo_bar').change(function() {
       if ($(this).val() == "Foo")
       {
           for (i=0; i<foo_specific_fields.length; i++)
           {
               show_field(foo_specific_fields[i]);
           }
           // hide "bar_specific_fields" here as well
       }
       else // it should be "Bar"
       {
           for (i=0; i<foo_specific_fields.length; i++)
           {
               hide_field(foo_specific_fields[i]);
           }
           // show "bar_specific_fields" here as well
   });
});

Note that i also have the same kind of sources, for fieldsets, in case
you need it.
There is probably some kind of better js library around, i obviously
failed to find it ...

--~--~---------~--~----~------------~-------~--~----~
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