(first posted: Aug 31, 2006)
(1975 Reads)
keywords: country list dropdown list
Permalink
Dropdown list property
The Dropdown List property is handy, lets you make dropdown lists. In the property validation you can specify the options in the format id,name;id,name (e.g. 1,apple;2,peach).
You can also specify a function that generates the options list, a number of modules provide a dropdown list user API function. So, for example, to get a list of articles of pubtype '12', the validation contains
xarModApiFunc( 'articles', 'user', 'dropdownlist', array('ptid'=>'12') )
Here's an anomoly. Lets say you made the $notes field a dropdown list. When you do a getall of your articles, $item['notes'] contains the aid of the option id (e.g 1, 2, or 3). But in the pubtype's display.xt template, $body contains the option name (e.g. apple, peach).
Here's another anomoly. When I print the value as [#$notes#], i expected to get [apple] but i get [ apple ]. Looking at the source, it's really this:
<!-- start: modules/base/xartemplates/properties/showoutput-dropdown.xd --> apple<!-- end: modules/base/xartemplates/properties/showoutput-dropdown.xd -->
because I have that option turned on in my themes config.
In one case, I need to lookup the rest of that item's data, so it looks like this:
<xar:set name="fruilt">xarModApiFunc('articles','user','get', array('pubtypeid'=>'12', 'title'=>trim(strip_tags($notes))))</xar:set>
Fortunately, strip_tags() which removes html tags from a string also removes html comments. Then trim() removes any leading and trailing white space chars.
UPDATE:
I recently checked in a change to the Country Dropdown property. Now you can add options to the property's validation, and these options will now appear at the top of the list.
Thus, you could put in the validation
us,United States;ca,Canada;uk,United Kingdom"
nd these will appear at the top of the country list, with the default value as
"United States", and the entire list below.
UPDATE:
Another recent change. The articles dropdownlist now has an argument 'showunpub' => '1' that allow non-admin to see unpublished articles. Without this argument, the arg 'status' => array(0,2,3) for example would be ignored unless you are logged in as an Admin. With the 'showunpub' set you can include unpublished articles in the dropdown list.
There are no comments attached to this item.



