Ignore:
Timestamp:
Jan 29, 2010, 10:02:16 AM (14 years ago)
Author:
gav
Message:

Add link option and field comments to CustomTagLib checkBoxList.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/taglib/CustomTagLib.groovy

    r290 r303  
    2626     *           this.assetSubItems = idList.collect { AssetSubItem.get( it ) }
    2727     *       }
     28     *
    2829     * Then a line in the controller:
    2930     *      assetInstance.setAssetSubItemsFromCheckBoxList(params.assetSubItems)
     31     *
     32     * Fields:
     33     *    name - the property name.
     34     *    from - the list to select from.
     35     *    value - the current value.
     36     *    optionKey - the key to use.
     37     *    displayFields - (optional) available options are 'id' and 'name', defaults to the objects toString().
     38     *    linkController - (optional, requires linkAction.) the controller to use for a link to the objects in the checkBoxList.
     39     *    linkAction - (optional, requires linkController.) the action to use for a link to the objects in the checkBoxList.
     40     *
     41     * Example:
     42     *    <!--
     43     *    <custom:checkBoxList name="assetSubItems"
     44     *                                    from="${AssetSubItem.list()}"
     45     *                                    value="${assetInstance?.assetSubItems.collect{it.id}}"
     46     *                                    optionKey="id"
     47     *                                    displayFields="['id', 'name']"
     48     *                                    linkController="assetSubItemDetailed"
     49     *                                    linkAction="show"/>
     50     *    -->
     51     *
    3052     */
     53
    3154    def checkBoxList = {attrs, body ->
    3255
     
    3760
    3861        def displayFields = attrs.displayFields
     62        def linkController = attrs.linkController
     63        def linkAction = attrs.linkAction
    3964
    4065        def displayValue = " "
     
    6085            displayValue = " "
    6186
    62             if( displayFields?.contains("id") ) {
     87            if( displayFields?.contains("id") )
    6388                displayValue += obj.id + " - "
    64             }
     89
     90            if(linkController && linkAction)
     91                   displayValue += "<a href=\"${createLink(controller: linkController, action: linkAction, id: obj.id).encodeAsHTML()}\">"
    6592
    6693            if(displayFields?.contains("name")) {
     
    6895            }
    6996            else displayValue += obj
     97
     98            if(linkController && linkAction)
     99                displayValue += '</a>'
    70100
    71101            // if we wanted to select the checkbox using a click anywhere on the label (also hover effect)
Note: See TracChangeset for help on using the changeset viewer.