0

I am trying to get a custom field type into the menu. I want this to be a dropdown which I poulate with some php code.

enter image description here Where the arrow points in want my dropdown field.

So I created in /components/com_hccxmlbeheer/models/fields/actiecode.php with the following code:

// Check to ensure this file is included in Joomla! defined('_JEXEC') or die('Restricted access');

jimport('joomla.form.formfield');

class JFormFieldActiecodes extends JFormField {

    protected $type = 'Actiecodes';

    // getLabel() left out

    public function getInput() {
        return '<select id="'.$this->id.'" name="'.$this->name.'">'.
            '<option value="1" >New York</option>'.
            '<option value="2" >Chicago</option>'.
            '<option value="3" >San Francisco</option>'.
            '</select>';
    }
 }

in default.xml of component frontend, I added the field:

<?xml version="1.0" encoding="utf-8"?> <metadata>
    <layout title="COM_HCCXMLBEHEER_HCCXMLBEHEER_VIEW_AANMELDFORM_TITLE">
        <message>COM_HCCXMLBEHEER_HCCXMLBEHEER_VIEW_AANMELDFORM_DESC</message>
    </layout>
    <fields name="request">
        <fieldset name="request" addfieldpath="components/com_hccxmlbeheer/models/fields">
            <field
                    addfieldpath="/components/com_hccxmlbeheer/models/fields"
                    name="actiecode"
                    type="Actiecodes"
                    label="COM_HCCXMLBEHEER_HCCXMLBEHEER_ACTIECODELABEL"
                    description="COM_HCCXMLBEHEER_HCCXMLBEHEER_ACTIECODEDESC"
            >
            </field>
        </fieldset>
    </fields> </metadata>

I see the field, but is not a dropdown and I can't select anything.

I also added to components/com_hccxmlbeheer/models/aanmeldformulier

JFormHelper::addFieldPath(JPATH_COMPONENT.'/models/fields');

What am I missing?

  • After many years of membership on Stackoverflow, thank you for coming to JSE. Please take our tour. – mickmackusa Mar 8 at 0:41
1

Rename actiecode.php to actiecodes.php.

Class name, filename and field type in XML form must all match.

| improve this answer | |
  • This was the solution, it was not clear in the documentation i found. i sugested an update. Thanks you verry mutch – Bas van den Dikkenberg Mar 7 at 16:56
  • Could you please provide the link to the document that was not clear enough? @Bas – mickmackusa Mar 8 at 1:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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