SomeoneS
SomeoneS

Reputation: 1279

Joomla 2.5 custom form field type

I am developing Joomla component, and i need custom form field type (Joomla 2.5) in admin area, but i have problem... It just won't work. Here is what i done so far:

File: /administrator/components/com_mycomponent/models/forms/history.xml

<form>

    <fields addfieldpath="/administrator/components/com_mycomponent/models/fields">

        <field
            name="id"
            type="hidden"
            default="0"
            required="true"
            readonly="true"/>                           

        <field 
            id="someid" 
            name="someid" 
            type="City" 
            label="City"
            description="Choose City"
            required="true" />

    </fields>   

</form>

File: /administrator/components/com_mycomponent/models/fields/history.php

<?php
defined('_JEXEC') or die('Restricted access');

jimport('joomla.form.formfield');

class JFormFieldCity extends JFormField {

        protected $type = 'City';

        // getLabel() left out

        public function getInput() {

            return '<select id="'.$this->id.'" name="'.$this->name.'">  <option value="1">City 1</option> </select>';
        }
}

And that is all i have changed. I use this tutorial: http://docs.joomla.org/Creating_a_custom_form_field_type (it is for Joomla 1.6, and i cant find anything "fresh"). Can someone tell me if i need more code somewhere or is something wrong with this code?

EDIT: i forgot to mention that this code outputs just input field.

Upvotes: 1

Views: 2748

Answers (2)

Riccardo Zorn
Riccardo Zorn

Reputation: 5615

Seems like the file should have been named city.php, not history.php.

Upvotes: 2

SomeoneS
SomeoneS

Reputation: 1279

Solved: i used this functionality instead of adding custom form field: http://docs.joomla.org/SQL_form_field_type

Upvotes: 0

Related Questions