J1.5 talk

Difference between revisions of "Using the JToolBar class in the frontend"

From Joomla! Documentation

(6 intermediate revisions by 4 users not shown)
Line 13: Line 13:
  
 
--[[User:Sbrandao|Sbrandao]] 13:20, 2 March 2009 (UTC)
 
--[[User:Sbrandao|Sbrandao]] 13:20, 2 March 2009 (UTC)
 +
 +
No,that's merely a HTML standard. See here: http://www.w3.org/TR/html4/interact/scripts.html#h-18.2.1 Language is, in fact, deprecated.
 +
 +
I am unsure as to why you found it to be like that; however, it might be related to your browser and testing setup.
 +
[[User:Daimonie|Daimonie]] 10:16, 23 August 2012 (CDT)
  
 
== Complete the toolbar look and feel ==
 
== Complete the toolbar look and feel ==
Line 52: Line 57:
  
 
Enjoy the toolbar!!!
 
Enjoy the toolbar!!!
 
+
== New notworking ==
 
'''"New" is a reserved word ergo you can't have a function called "new" you will get a syntax error that wont go away. So you need to change the name of the "task" "new" to something like "mynew" and then the function to "mynew" also.'''
 
'''"New" is a reserved word ergo you can't have a function called "new" you will get a syntax error that wont go away. So you need to change the name of the "task" "new" to something like "mynew" and then the function to "mynew" also.'''
  
Line 91: Line 96:
  
 
--[[User:Rolfz|Rolfz]] 13:56, 21 August 2011 (CDT)
 
--[[User:Rolfz|Rolfz]] 13:56, 21 August 2011 (CDT)
 +
'''Added a section on this. The fix is to define your own 'standard' button with a changed HTML function.
 +
--[[User:Daimonie|Daimonie]] 18:07, 8 Octobre 2012 (GMT+1)
 +
 +
== Javascript and Forms ==
 +
 +
You can add the form in the default.php since Joomla builds the view and appends the toolbars from the controller onto one page. When a button on the toolbar is clicked, it submits the form via javascript. To verify view your HTML source. You should see the HTML rendering the toolbars javascript and the form definition on the same page.
 +
 +
The new keyword is reserved. I changed mine to add
 +
 +
--[[User:EduOngeso|EduOngeso]] 17:34, 28 September 2011 (CDT)
 +
 +
== id of adminForm is misleading ==
 +
 +
This documentation helped me show the toolbar on the front end, but when I tried to save the form it just didn't pass any data to the save function in the controller. The cancel button worked well. After days of frustration, the answer turned out to be really simple.
 +
 +
The following comment is very misleading:
 +
"the toolbar MUST be in a form with the id of "adminForm" in order for it to work."
 +
 +
In fact, I found that the form that you need to submit needs to have id="adminForm", and the toolbar itself needs to have a different id (I called mine id="adminForm2"). Now my form actually saves the data, and doesn't just complain about mandatory fields which already have data in them. Hopefully this tip can save someone else hours of frustration.

Revision as of 10:17, 23 August 2012

javascript[edit]

Hi,

This is a great article :) However I had a small problem due to my lack of experience... I propose a small change in the javascript part: Instead of <script type="text/javascript" src="includes/js/joomla.javascript.js"></script>, shouldn't it be: <script language="javascript" type="text/javascript" src="includes/js/joomla.javascript.js"></script> ?

Since I am quite new to web development (including html and php) it took me some time to understand that the reason behind my buttons inactivity was the language attribute... I do not know if this is a general feature or if it depends on the developer's configurations... either way, probably this should be mentioned on the article.

--Sbrandao 13:20, 2 March 2009 (UTC)

No,that's merely a HTML standard. See here: http://www.w3.org/TR/html4/interact/scripts.html#h-18.2.1 Language is, in fact, deprecated.

I am unsure as to why you found it to be like that; however, it might be related to your browser and testing setup. Daimonie 10:16, 23 August 2012 (CDT)

Complete the toolbar look and feel[edit]

Thanks to the original contributor; very nice piece explaining how we can add the menu to the front end. I would like to add the following to give a more complete picture.

Changes to CSS Copy the contents from the following CSS into the new CSS you are creating for your component.

From directory /joomla/administrator/templates/khepri/css

  1. rounded.css or norounded.css as needed (you can copy both if you could be using either of them)
  2. general.css
  3. you can ignore the additions for table.toolbar a and table.toolbar a:hover they are already in general.css. However, you need to have the code for icons

The code copied from general.css has the styles for div.header. By default the color is #0B55C4, change this to your color of choice

Changes to com_yourcomponent.php

echo "<div id=\"toolbar-box\">\n";
echo "<div class=\"t\">\n";
echo "<div class=\"t\">\n";
echo "<div class=\"t\"></div>\n";
echo "</div></div>\n";
echo "<div class=\"m\">\n";
echo yourcomponentHelperToolbar::getToolbar( );
echo "<div class=\"header\">menu header</div>\n";
echo "<div class=\"clr\"></div>\n";
echo "</div>\n";
echo "<div class=\"b\">\n";
echo "<div class=\"b\">\n";
echo "<div class=\"b\"></div>\n";
echo "</div>\n";
echo "</div>\n";
echo "</div>\n";

This will make sure that the look and feel is exactly like the backend.

Enjoy the toolbar!!!

New notworking[edit]

"New" is a reserved word ergo you can't have a function called "new" you will get a syntax error that wont go away. So you need to change the name of the "task" "new" to something like "mynew" and then the function to "mynew" also.

Hey, something is not working with the function name new():

function new()

  {
     JRequest::setVar('view' , 'new');
     parent::display();
  }


Parse error: syntax error, unexpected T_NEW, expecting T_STRING in D:\htdocs\cattleinfo\components\com_breed\controller.php on line 7

so..we need to change the function name first, or yu guys have other option to solve this problem.

Its quite confussing where to insert the following form, is it inside default.php

<form action = "index.php" method = "post" id = "adminForm" name = "adminForm" />

<input type = "hidden" name = "task" value = "" />
<input type = "hidden" name = "option" value = "com_yourcom" />
</form>

thukten dendup

Problem with toolbar and SEO[edit]

Hi

I was very happy when I saw the chapter on using JToolBar in 1.6 – everything looked so easy! But, although the description is very good and nothing is missing, I needed a long time until it worked as expected in my tests.

My problem was: In my installation, I had SEO (Search Engine Friendly URLs) set to „Yes“ – and this somehow mixed up the parameters sent by the edit form (but not in the list form - these buttons worked): option, task and all the other parameters somehow got lost and were never seen by a controller, so „save“ and „cancel“ never worked correctly. After changing this setting, almost everything worked on first try.

The one exception ist the toolbar title: it is never displayed in the front end. Is this the same for everybody or just another problem with my site only?

Many thanks for this article – having all the toolbar functionality easily available in the frontend helps me a lot.

--Rolfz 13:56, 21 August 2011 (CDT) Added a section on this. The fix is to define your own 'standard' button with a changed HTML function. --Daimonie 18:07, 8 Octobre 2012 (GMT+1)

Javascript and Forms[edit]

You can add the form in the default.php since Joomla builds the view and appends the toolbars from the controller onto one page. When a button on the toolbar is clicked, it submits the form via javascript. To verify view your HTML source. You should see the HTML rendering the toolbars javascript and the form definition on the same page.

The new keyword is reserved. I changed mine to add

--EduOngeso 17:34, 28 September 2011 (CDT)

id of adminForm is misleading[edit]

This documentation helped me show the toolbar on the front end, but when I tried to save the form it just didn't pass any data to the save function in the controller. The cancel button worked well. After days of frustration, the answer turned out to be really simple.

The following comment is very misleading: "the toolbar MUST be in a form with the id of "adminForm" in order for it to work."

In fact, I found that the form that you need to submit needs to have id="adminForm", and the toolbar itself needs to have a different id (I called mine id="adminForm2"). Now my form actually saves the data, and doesn't just complain about mandatory fields which already have data in them. Hopefully this tip can save someone else hours of frustration.