in reply to populating <select multi="1"> from ORM

Sounds like your list needs to become a hash, with stuff like { barney => 0, fred => 0, dino => 1, betty => 1 } as in, "... and these items are selected". And then you can map the keys, and look up each value to see whether to add selected=1 or not.

You can even have a legacy call that creates the hash for the new call, so that you have to maintain only one piece of TT code. The legacy call would would take a list and a 'selected', and generate a call to the new call with a hash that has only 0 or 1 'selected' set to 1.

Replies are listed 'Best First'.
Re^2: populating <select multi="1"> from ORM
by abs0 (Beadle) on Jul 09, 2007 at 17:40 UTC
    I'm assuming you suggesting all this lookup happens in perl rather than TT. That would be a list of hashrefs, as when presenting the <options> in the <select> I need to have the correct order, and each element would need to have at least
    • value
    • display name
    • selected
    Thats pretty much where I'd ended up, it just feels a little unclean to convert an array of objects to an array of hashrefs in order to pass to TT. Thats probably just me viewing everything as 'should be Object nail' since I bought into the OO-perl hammer :)