Version 4 (modified by Fran Boon, 11 years ago) ( diff )



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/

Massimo has put back-end sorting into 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:

  • This works with capitalised/non merged but means that the NULL in IS_NULL_OR() isn't the default:
         jQuery(this).html(jQuery(this).children("option").sort(function(a,b) {
           return (a.text.toUpperCase() == b.text.toUpperCase())?0:((a.text.toUpperCase() < b.text.toUpperCase())?-1:1);
          // jQuery(this).children("option:first").attr("selected","selected");

Q: Where does one put page-specific Javascript ?
A: views/module/resource_method.html

For Dictionary-based ones can:

In  models/ change:

or_organisation_type_opts = {
   2:T('International Governmental Organization'),
   3:T('International NGO'),
   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))


or_organisation_type_opts = [
   (2,T('International Governmental Organization')),
   (3,T('International NGO')),
   (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]))
Note: See TracWiki for help on using the wiki.