Backend Custom Form Field Type - Call to a member function getFieldset() on a non-object

867 views
Skip to first unread message

Neo314

unread,
Feb 17, 2013, 3:39:15 PM2/17/13
to joomla-de...@googlegroups.com
The documentation on this subject seems thin. I read the thread here on a similar problem, but something else is happening to me.

I am trying to create a database populated select list (pretty basic really).
After having no luck on this problem, I have reduced it to a basic example and still get the same error.

myform.xml
<fieldset name="essential" addfieldpath="/administrator/components/com_mycomp/models/fields">
...
<field name="myicon_image"
type="iconimagelist"
label="COM_MYCOMP_FIELD_MYFORM_ICON_IMAGE_LABEL"
description="COM_MYCOMP_FIELD_MYFORM_ICON_IMAGE_DESC"
id="myicon_image"

/administrator/components/com_mycomp/models/fields/iconimagelist.php (Straight out of the example modified the name)

<?php
// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die('Restricted access');
 
jimport('joomla.form.formfield');
 
class JFormFieldIconimagelist extends JFormField {
 
        protected $type = 'iconimagelist';
 
        // 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>';
        }
}

 
/administrator/components/com_mycomp/views/myform/tmpl/edit.php on line 7:
<?php foreach ($this->form->getFieldset('essential') as $field): ?>

The error comes back as
 Call to a member function getFieldset() on a non-object in E:\_WEB\joomla\administrator\components\com_mycomp\views\myform\tmpl\edit.php on line 7

What I would really like to do is get the type to act as a list and just override the method to get the options, but I am having no luck with either approach.

WHEN I REMOVE THE FIELD FROM THE XML FILE, THE FORM WORKS, so I considering that to confirm the problem is only with the custom field type issue.

Any help would be greatly appreciated.

Neo314

unread,
Feb 17, 2013, 3:40:33 PM2/17/13
to joomla-de...@googlegroups.com

Neo314

unread,
Feb 17, 2013, 3:48:45 PM2/17/13
to joomla-de...@googlegroups.com
I solved the main problem. A big DUH. I did not close the field correctly.

I would still prefer to override the getOptions. Any advice on a better reference or method would be appreciated.

Don

unread,
Feb 17, 2013, 4:19:10 PM2/17/13
to joomla-de...@googlegroups.com
That's what I was going to say. :)

If you want to make a list drop down, just extend JFormFieldList instead. Look at JFormFieldSql as well to see how they do it there. (Hint: you have to make sure the list class is loaded before you try to extend it. 

Sent from my iPhone
--
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.
 
 

Neo314

unread,
Feb 17, 2013, 5:02:33 PM2/17/13
to joomla-de...@googlegroups.com
Thanks. After solving my goof, I got it already from here: http://forum.joomla.org/viewtopic.php?p=2518975, including the problem mentioned there that the dot notation did not work for the import.

My query is conditional:
$query->select("content_id as value, IF(content_name != '', content_name, content_location) as text");

because content name may be empty in which case it uses the file name (file upload is my next challenge).

SOOOOooo... My problem now is how to escape the text field properly. I mean I could use htmlentities or htmlspecialchars, but I cannot identify how to escape the field with Joomla's built in methods. The code below does not work, so where do I need to reach to to get the escape function. BTW, I just started looking into this question, so I have not really given my own efforts a chance at this point :o)

foreach ($options as $key => $option) {
 $options[$key]->text = $this->escape($option->text);

Neo314

unread,
Feb 17, 2013, 5:04:34 PM2/17/13
to joomla-de...@googlegroups.com
BTW, I would have thought that the getOptions would have escaped the text field automatically.

Neo314

unread,
Feb 17, 2013, 5:10:13 PM2/17/13
to joomla-de...@googlegroups.com
Scratch that. It looks like it is escaping the output. Firebug shows it not escaped, but it is escaped (entitied) in the source.
Reply all
Reply to author
Forward
0 new messages