OK, I solved #1. Indeed, the solution is trivial, but I had to trouble
this group in order to get to it - as always :(.

Here's the solution, in case anyone may find it helpful. It's a JS
defined using the model's js attribute. I'm not much of a JS coder, so
please don't hold the quality of this code against me :).

addEvent(window, 'load', hide_other); // Register a callback to when
the page has been loaded.
var other_index = 0; // Index of the option that triggers the other
field display
var type_field; // The field that triggers the display
var other_field; // The field that is displayed

function change_handler()
{
    if (type_field.selectedIndex == other_index) {
        other_field.parentNode.style.display = ''
    } else {
        other_field.parentNode.style.display = 'none'
    }
}

function hide_other()
{
    other_field = document.getElementById('id_other_workout_type');
    div = other_field.parentNode;
    div.style.display = 'none'

    type_field = document.getElementById('id_workout_type');
    for (i = 0; i < type_field.length; i++) {
        if (type_field.options[i].text == 'Other') {
            other_index = i;
        }
    }
    if (type_field.addEventListener) {
        type_field.addEventListener("change", change_handler, false);
    } else if (type_field.attachEvent) {
        type_field.attachEvent("onchange", change_handler);
    } else {
        type_field.onchange =  change_handler;
    }
}


On Apr 25, 11:57 pm, dimrub <[EMAIL PROTECTED]> wrote:
> Greetings, all!
>
> Two (possibly - trivial) questions regarding a field that has
> 'choices' defined for it.
>
> 1. Is there a way to specify a special choice, upon which another
> field becomes active? A typical use case is to have a certain set of
> predefined values (out of which the user will USUALLY choose) and
> allow the user to override it with whatever pleases him. I was
> thinking of some sort of JS solution, but I can't think of an easy way
> to integrate it with the admin interface.

--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to