== AlphaSort == Want to be able to sort a Dropdown alphabetically to make it easier for data entry e.g. the Organisations dropdown in 'Add Office' We have 2 sorts of dropdowns: * Database * Dictionary This one is a Database one using the IS_ONE_OF() custom validator from {{{modules/s3/s3validators.py}}} Massimo has put back-end sorting into [http://bazaar.launchpad.net/~mdipierro/web2py/devel/revision/1543 Trunk]: * IS_IN_SET(..., sort=True) and/or IS_IN_DB(..., sort=True) * needs porting to IS_ONE_OF() * needs testing Foront-end sorting can be done with JS: * http://stackoverflow.com/questions/278089/javascript-to-sort-contents-of-select-element/278509#278509 * This works with capitalised/non merged but means that the NULL in IS_NULL_OR() isn't the default: {{{ }}} Q: Where does one put page-specific Javascript ?[[BR]] A: {{{views/module/resource_method.html}}} For Dictionary-based ones can: {{{ In models/05_or.py change: or_organisation_type_opts = { 1:T('Government'), 2:T('International Governmental Organization'), 3:T('International NGO'), 4:T('Misc'), 5:T('National Institution'), 6:T('National NGO'), 7:T('United Nations') } ... db[table].type.requires = IS_NULL_OR(IS_IN_SET(or_organisation_type_opts)) into or_organisation_type_opts = [ (1,T('Government')), (2,T('International Governmental Organization')), (3,T('International NGO')), (4,T('Misc')), (5,T('National Institution')), (6,T('National NGO')), (7,T('United Nations')) ] ... db[table].type.requires = IS_NULL_OR(IS_IN_SET( [x[0] for x in or_organisation_type_opts], [x[1] for x in or_organisation_type_opts])) }}}