Hi!


It is not uncommon to have a set of elements that are dependent on previous
selections and get populated with some dynamic information accordingly to the
selections made before.  

To illustrate this "problem", I'll be using <SELECT> and <OPTION> elements,
but this could be applied to other combinations as well.

One common case that helps to explain the idea is the relationship that exists
between countries, states and cities.  If I select a country I'd like to show
all states that belong to this country and all cities that belongs to each
state.  If I change the selection I want that the states select be populated
with new data and then the cities select also be changed.

For the first change, countries -> states, an onchange event is fine and it
can replace the values "instantly".

Now comes the problem:

    - what is the best way to have the cities select changed?

Today I'm doing a "signal('state', 'onchange');" after updating the state
select has changed BUT here I have to deal with two problems:

    - countries that have no state records on the database

    - slow connections


The first problem forbids me to signal the event on the callback since it will
never be called because there are no records to be returned (should the
developer return something and discard it on these situations?  It is one
solution that I haven't thought about before...) and then the cities select
would be populated with garbage from my previous selection.

The second problem arrives when I signal the change before the callback is
called, so when the other event is triggered there's no value to ask to the
database the next set of dependent records.  I can use a loop rescheduling the
same with using a callLater() and calling the event itself again with all
parameters it received.  Unfortunately, this might cause problems when there
are really no records to retrieve because an infinite loop will start where
the function will be called every X seconds (should some kind of loop counter
be used here to terminate the loop after, e.g., 10 sucessive calls without
return from the server?).

So, to solve this problem of "garbage" cleaning for the cities field should
one person:

    a) always return something from the called function so that the deferred
       function is called?

    b) use some sort of counter to break the loop and use the callLater
       approach? 


The problem can be extended if I have a varied number of dependents
(e.g. countries -> states -> cities -> zones -> streets --- where I have just
part of the form in some places and it fully present in other places or even
two "instances" of it for different kinds of information (think business and
home address, for example) in the same form). 


I tend to the a) approach...  Is it the best one?  Is there another option
that is better to solve this kind of problem?


Thanks for any input on that subject,
-- 
Jorge Godoy      <[EMAIL PROTECTED]>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"MochiKit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/mochikit
-~----------~----~----~----~------~----~------~--~---

Reply via email to