Results 1 to 4 of 4

Thread: Member Select Menu Field and Option Groups

  1. #1
    Experienced user
    Join Date
    08-21-09.
    Posts
    563

    Default Member Select Menu Field and Option Groups

    Hi all,

    I am stuck on this small thing...

    I've created a custom member field. It's a select menu that pulls from the database. I'm using the options_callback to do this.

    In the front-end, I need it's options to be grouped in <optgroup> fields.

    When I return something like:
    Code:
    array('Group' => array('Option 1', 'Option 2', 'Option 3'))
    It works fine in the back-end, but not in the front-end (the options are blank).

    I've also tried returning an array like the one generated by an ordinary front-end select widget (associative array with 'value', 'label', and optional 'group' keys), but no dice here either.

    Does anyone know how to do this (or if it's even possible)?
    Brian

  2. #2
    Experienced user
    Join Date
    06-20-09.
    Posts
    1,311

    Default Re: Member Select Menu Field and Option Groups

    Not sure - but do any of these field eval options help you....

    feEditable - If true the current field can be edited in the frontend. Applies to table tl_member only.
    feGroup -Applies to table tl_member only. You can also define your own groups.
    feViewable - If true the current field is viewable in the member listing module

  3. #3
    Experienced user
    Join Date
    06-20-09.
    Posts
    1,311

    Default Re: Member Select Menu Field and Option Groups

    Here is an options callback that works for me in frontend (nothing to do with members though) Both are in a class PaypalkeyForm.php

    Code:
    			
    $arrFields['product'] = array
    (
     'name' 	 => 'product_'.$strFormId,	
     'label' 	 => $GLOBALS['TL_LANG']['tl_paypalkey']['ppk_label_product'],
     'inputType'               => 'select',
     'options_callback'        => array('PaypalkeyForm', 'products_callback'),
     'eval'                    => array('includeBlankOption'=>true, 'mandatory'=>true)//, 
    );
    Code:
    	public function products_callback()
    	{
    		$arrRet = array();	
    		//SELECT PRODUCTS
    		$qry =  "SELECT * FROM tl_paypalkey_products";
    		$objRow = $this->Database->prepare($qry)->execute();
            
    		while ($objRow->next())
    		{
    			$arrRet[$objRow->id] = $objRow->select_name . ' [' . $objRow->amount . ']';
    		}
    		
    		return $arrRet;
    	}

  4. #4
    Experienced user
    Join Date
    08-21-09.
    Posts
    563

    Default Re: Member Select Menu Field and Option Groups

    Hey, Thanks for the hand.

    I can get the options callback to work fine on both sides, as long as it's a flat list (like in your example). But I was asked to group those options into "<optgroup>" tags, and that's where I got stuck.

    It's easy in the back-end -- just a nested array does the trick. But the same array does not render at all in the front-end. And with normal FE select widgets, it's not too hard to do either (with 'group' => 1). But this seems to obey neither method.

    I got something working (just so I could move on), but it's pretty awful. I used a template hook, regex'ed out the entire select menu, and replaced it with a completely new FE widget instead that rebuilds the options all over again. :?

    So yeah, if anyone knows of a more elegant way, I'd appreciate it.

    Thanks!
    Brian

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •