5

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>
2
  • 1
    Rename your file name to lower case city.php
    – Nagarjun
    Dec 11, 2017 at 14:41
  • Maybe your development machine is Windows (which has case insensitive file names) and everything works there but you deploy to Linux (case sensitive file names) and it fails? Keep your names lowercase (as @Nagarjun mentioned)
    – ed22
    Apr 15, 2020 at 9:28

2 Answers 2

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 (as commented under the question). Basically, every file in Joomla should be lowercase.

The Windows file system is not case sensitive, while Linux is.

Change City.php to city.php.

0
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 and acknowledge you have read our privacy policy.

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