3

My attempt is to re-build the example here: https://docs.joomla.org/Creating_a_custom_form_field_type

Somehow, Joomla doesn't see the City.php file in administrator/components/com_testing/models/fields. Even when I force a syntax error inside the City.php file (e.g. deleting an ; at the end of a line), no error is displayed. So I am assuming the City.php file isn't even included.

I tried to include the new field path via addfieldpath in fieldset-definition and also with JForm::addFieldPath(JPATH_COMPONENT . '/models/fields'); in the model's getForm-function. Nothing worked so far.

The output is a text input field, which I do not want.

Here is my source code:

City.php file is equivalent to the one in the link above.

administrator/components/com_testing/models/forms/testing.xml:

<?xml version="1.0" encoding="utf-8"?>
<form>
    <fieldset addfieldpath="/administrator/components/com_testing/models/fields">
        <field
            name="testingfield"
            type="City"
            multiple="true"
            size="7"
            label="Testinglabel">
                    <option value="A">A</option>
                    <option value="B">B</option>
                    <option value="C">C</option>
                    <option value="D">D</option>
                    <option value="E">E</option>
                    <option value="F">F</option>
                    <option value="G">G</option>
        </field>
    </fieldset>
</form>
  • Rename your file name to lower case city.php – Nagarjun Dec 11 '17 at 14:41
2

If you field is in the administrator, you want to use this include path: JFormHelper::addFieldPath(JPATH_COMPONENT_ADMINISTRATOR.'/models/fields');

  • Oh and you want that filename to be lowercase per @Pratyush. Basically, every file in Joomla should be lowercase. – David Hayes Dec 12 '17 at 22:24
  • Oh my god. Thank you. I spent an hour guessing, why does it work on Windows and doesn't work on Linux. Windows file system is not case sensitive, while Linux is. Lowercasing solved the issue. – user4035 Mar 3 '18 at 23:54
  • Your welcome, glad to hep. – David Hayes Mar 7 '18 at 19:40
1

Set the type to city in lowercase, and if it doesn't still work try adding addfieldpath to the field as

<?xml version="1.0" encoding="utf-8"?>
<form>
    <fieldset>
        <field
            addfieldpath="/administrator/components/com_testing/models/fields"
            name="testingfield"
            type="City"
            multiple="true"
            size="7"
            label="Testinglabel">
                    <option value="A">A</option>
                    <option value="B">B</option>
                    <option value="C">C</option>
                    <option value="D">D</option>
                    <option value="E">E</option>
                    <option value="F">F</option>
                    <option value="G">G</option>
        </field>
    </fieldset>
</form>

as in some cases the fieldset path cannot be accessed.

Also check the FormField file that you are using and match the cases as in the example file.

In one case I have faced an issue the formfield doesn't not load, so also try to make a same file with some other type eg : replace city with Example and do not forget to match the case.

Hope this helps.

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.