| 1 | == AlphaSort == |
| 2 | |
| 3 | Want to be able to sort a Dropdown alphabetically to make it easier for data entry |
| 4 | e.g. the Organisations dropdown in 'Add Office' |
| 5 | |
| 6 | We have 2 sorts of dropdowns: |
| 7 | * Database |
| 8 | * Dictionary |
| 9 | |
| 10 | This one is a Database one using the IS_ONE_OF() custom validator from {{{modules/validators.pty}}} |
| 11 | |
| 12 | js list sorter: |
| 13 | * http://stackoverflow.com/questions/278089/javascript-to-sort-contents-of-select-element/278509#278509 |
| 14 | |
| 15 | As far as sorting right in the backend is concerned - models/05_or.py line 107, tried putting .select(orderby = db.or_organsation.name)[0]... |
| 16 | But that did not work out... |
| 17 | |
| 18 | Q: If its possible to put a javascript fix where does one put a page specific js ?[[BR]] |
| 19 | A: {{{views/module/resource_method.html}}} |
| 20 | |
| 21 | For Dictionary-based ones: |
| 22 | {{{ |
| 23 | In models/05_or.py change: |
| 24 | |
| 25 | or_organisation_type_opts = { |
| 26 | 1:T('Government'), |
| 27 | 2:T('International Governmental Organization'), |
| 28 | 3:T('International NGO'), |
| 29 | 4:T('Misc'), |
| 30 | 5:T('National Institution'), |
| 31 | 6:T('National NGO'), |
| 32 | 7:T('United Nations') |
| 33 | } |
| 34 | ... |
| 35 | db[table].type.requires = IS_NULL_OR(IS_IN_SET(or_organisation_type_opts)) |
| 36 | |
| 37 | into |
| 38 | |
| 39 | or_organisation_type_opts = [ |
| 40 | (1,T('Government')), |
| 41 | (2,T('International Governmental Organization')), |
| 42 | (3,T('International NGO')), |
| 43 | (4,T('Misc')), |
| 44 | (5,T('National Institution')), |
| 45 | (6,T('National NGO')), |
| 46 | (7,T('United Nations')) |
| 47 | ] |
| 48 | ... |
| 49 | db[table].type.requires = IS_NULL_OR(IS_IN_SET( |
| 50 | [x[0] for x in or_organisation_type_opts], |
| 51 | [x[1] for x in or_organisation_type_opts])) |
| 52 | }}} |