From: Roy J. <RJo...@sp...> - 2004-07-10 15:57:36
|
> Hello, >=20 > I realized that when using HTMLForm::selectList that the items in the = list were returned in an unsorted order. For a particular form I'm = creating, I needed the items in the list to be sorted by the 'value' of = the options hash. Attached is some code that does this. (alphabetically = ascending case-insensitive) >=20 > Basically, when you call selectList from Form.pm you pass an additional = parameter: >=20 > sortByValue =3D> 1 >=20 > I haven't actually used this in a WebGUI site yet because I wanted to = run this by you guys before I got too excited. The attached script simply = prints the generated HTML to stdout and demonstrates a simple example. >=20 > Thanks, >=20 > Roy >=20 >>It's a good idea to include this functionality in the actual selectList= =20 method, but I think you can make it a bit shorter. Check out the=20 Tie::IxHash module which is actually used all over the place in WebGUI=20 already to sort select lists. I don't think anyone thought to include=20 it in the actual selectList method yet though for some reason. :) Check out the attached script. >> >> -Andy Okay, I didn't know it was possible to make a hash keep elements in any = kind of order. All of my Perl books have been beating the idea into my = head that 'Hashes have no order except the order that perl likes' so I = appreciate your feedback. I will re-implement my idea using your suggested method as it will be = cleaner and easier to follow in the code. This time will also update the = POD and test on our development site. If all goes well, I will repost. Thanks again, Roy |