Re: Jtoolbarhelper HELP

382 views
Skip to first unread message

Glenn Arkell

unread,
Feb 12, 2013, 3:23:29 PM2/12/13
to joomla-de...@googlegroups.com
Hi Seeward,

The only thing I can suggest (still learning MVC myself) is to change the "protected $view_list = 'courses';" line in your controller to

    function __construct() {
        $this->view_list = 'courses';
        parent::__construct();
    }

Give this a try.  I'll be watching to see what others may suggest which will assist my learning also.  Cheers.

Glenn

On Wednesday, February 13, 2013 2:34:57 AM UTC+11, seeward wrote:
I am rather new to Joomla development and have been slowly working on a simple MVC Component. All was going well until I began to try to edit data from the database. The SAVE and CANCEL buttons do not do anything when clicked.

I have an edit view:
Code:
<?php
defined( '_JEXEC' ) or die;

jimport( 'joomla.application.component.view');

class CoursesViewCourse extends JViewLegacy
{
   protected $item;
   protected $form;

   public function display($tpl = null)
   {
      $this->item = $this->get('Item');
      $this->form = $this->get('Form');

      $this->addToolbar();

      parent::display($tpl);
   }

   public function addToolbar()
   {
      if ($this->item->course_id) {
         JToolBarHelper::title(JText::_('COM_EXPLORE_EDIT_ACTIVITIES_TITLE'));
      } else {
         JToolBarHelper::title(JText::_('COM_EXPLORE_ADD_ACTIVITIES_TITLE'));
      }


      JToolBarHelper::save('course.save');


      JToolBarHelper::cancel('course.cancel');
   }
}


Then I have a controller called 'course' as above attached to the JToolBarHelper::save and ::cancel functions:
Code:
<?php
defined( '_JEXEC' ) or die;

jimport('joomla.application.component.controllerform');

class CoursesControllerCourse extends JControllerForm
{
   protected $view_list = 'courses';
}


I am able to pull in the data from the database when I click on an individual item in the 'courses' view but the button dont function whether I am editing or creating a new record. If I am correctly understanding the syntax then the JToolBarHelper is a method within the JControllerForm class. So I don't need to add any functions to the ::save and ::cancel because they are part of the parent class. Is this correct?

Any advice on what I may be missing?

Thanks,

seeward

Olivier Nolbert

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

You're right, you don't have to declare the save() function as it's declared in the JControllerForm class and it's not abstract.

What you could do to test is to declare it just to try it's called by your code :

public function save($key = null, $urlVar = null)
{
#Some code that raises error or displays debug info#
}

You could also check if there's no JS error on save button click.

Olivier


2013/2/12 Glenn Arkell <glenn...@gmail.com>
--
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

Christian McCabe

unread,
Feb 12, 2013, 5:14:41 PM2/12/13
to joomla-de...@googlegroups.com
Thanks for the feedback gentlemen!

I am getting this error in the console when I click one of the buttons:

Uncaught TypeError: Cannot read property 'task' of null

I guess it's javascript? Looks like the button's are not firing off their tasks?

Don't know where to turn now...
Kind Regards,

Christian McCabe

Rune V. Sjøen

unread,
Feb 12, 2013, 6:02:48 PM2/12/13
to joomla-de...@googlegroups.com
You need to wrap it all in a <form> with id/name="adminForm" and which provide a <input type="hidden" name="task"/>

Take a look here for an example.


The toolbar buttons attempt to submit that form with the task specified in the button.

- Rune


2013/2/12 Glenn Arkell <glenn...@gmail.com>
To unsubscribe from this group and stop receiving emails from it, send an email to joomla-dev-general+unsub...@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

--
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-general+unsub...@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.
 
 

Christian McCabe

unread,
Feb 12, 2013, 11:37:01 PM2/12/13
to joomla-de...@googlegroups.com
I really appreciate the suggestions. @rune, I am calling the buttons in a form called edit.php

<?php defined( '_JEXEC' ) or die; ?>
<form action="index.php?option=com_courses&amp;course_id=<?php echo $this->item->course_id ?>"
method="post" name="adminForm" class="form-validate">
<div class="width-60 fltlft">
<fieldset class="adminform">
<ul class="adminformlist">
<?php foreach ($this->form->getFieldset() as $field): ?>
<li><?php echo $field->label; ?>
<?php echo $field->input; ?></li>
<?php endforeach ?>
</ul>

</fieldset>
</div>
<input type="hidden" name="task" value="" />
<input type="hidden" name="boxchecked" value="0" />
<?php echo JHtml::_('form.token'); ?>
</form>


I have tried it without <input type="hidden" name="boxchecked" value="0" /> but same error :
Uncaught TypeError: Cannot read property 'task' of null

Could this have to do with User permissions? I haven't added any code to check user rights but I was assuming that would be covered in the <?php echo JHtml::_('form.token'); ?> statement?

Michael Babker

unread,
Feb 12, 2013, 11:51:42 PM2/12/13
to joomla-de...@googlegroups.com
Try adding id="adminForm" to the <form> tag.  I can't remember when we did it or what's "right" anymore, but I know something was changed to start phasing out name="adminForm".

--
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.

Christian McCabe

unread,
Feb 13, 2013, 12:00:31 AM2/13/13
to joomla-de...@googlegroups.com
@Michael - that was it! Thanks so much... Now I can move forward with my first component!

People are AWESOME!
Reply all
Reply to author
Forward
0 new messages