Re: [jgen] Joomla 2.5 custom form field type problem

283 views
Skip to first unread message

Olivier Nolbert

unread,
Feb 13, 2013, 3:19:13 PM2/13/13
to joomla-de...@googlegroups.com
Hi,

If your 'City' field correctly displays the select list with 1 option, I think your custom field class is correctly set.

What you could check is if your field name is correct in the form html code and if it's the same name in the DB table.

Olivier


2013/2/13 JohnnyNT <john...@gmail.com>
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? (this code outputs just input field, and when i change value and save it, i can see that it is not saved in database).

--
You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to joomla-dev-gene...@googlegroups.com.
To post to this group, send an email to joomla-de...@googlegroups.com.
Visit this group at http://groups.google.com/group/joomla-dev-general?hl=en-GB.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Olivier Nolbert, Jiliko
14 passage Lecroisey 76600 Le Havre, France
SIREN : 517 564 365

JohnnyNT

unread,
Feb 13, 2013, 3:26:19 PM2/13/13
to joomla-de...@googlegroups.com
Hi Oliver,

Thanks for your reply. In the meantime i found other, much simpler solution: http://docs.joomla.org/SQL_form_field_type
I wanted to call select box options from database anyway, so this is great solution for my needs.

Swapnil Shah

unread,
Feb 13, 2013, 3:30:04 PM2/13/13
to joomla-de...@googlegroups.com
Rename history.php to city.php that should do the trick. 

Regards, 


Neil
Sent from my iPhone

Olivier Nolbert

unread,
Feb 13, 2013, 3:53:35 PM2/13/13
to joomla-de...@googlegroups.com
@Neil : you got eagle eyes. I missed this one :-)


2013/2/13 Swapnil Shah <swapni...@gmail.com>

JohnnyNT

unread,
Feb 13, 2013, 4:02:29 PM2/13/13
to joomla-de...@googlegroups.com
 @Neil  i renamed it (just wanna see if it works, because i already find the solution), and it works, you got eagle eyes  x2 :)

Swapnil Shah

unread,
Feb 14, 2013, 9:29:46 AM2/14/13
to joomla-de...@googlegroups.com
Glad I could help. 

A debugger is extremely helpful! Silly errors like that will drive you bananas! 


Regards, 


Neil
Sent from my iPhone
Reply all
Reply to author
Forward
0 new messages