1

Maybe is a simple question but, in my form, I not able to set the "selected" value, in my SELECT element: The following is my code:

CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($financialTypes, 3);
$this->add('select', 'financial_type', ts('Financial Type'), $financialTypes, 'TRUE');

2 Answers 2

3

This is how you do it:

CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($financialTypes, 3);
    $this->add('select', 'financial_type', ts('Financial Type'), 
            $financialTypes, 
            'TRUE'
            );
    $this->_elements[4]->setSelected(9);

You need to inspect $this and determine which of the elements is the select you want to modify. In my case it was the 4th one.

You then need to inspect the select (from the browser) and find out the value for the option that you want selected by default.

0
$this->add('select', 'financial_type', ts('Financial Type'), 
            $financialTypes, 
            'TRUE'
            )->setSelected(9);

You can set selected item directly this way.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.