Welcome, Guest
Username: Password: Remember me

TOPIC: [FIXED] Toggle + authoring

[FIXED] Toggle + authoring 08 May 2012 12:30 #2284

  • Tomaselli
  • Tomaselli's Avatar
  • Offline
  • Elite Member
  • Posts: 293
  • Thank you received: 87
  • Karma: 46
Hi Admin,
I'm not in the position of tell you what to do, so I apologize in advance for the following review, it's just a way to give you an idea on how fix quickly the following bugs.

scenario:

- table with authoring feature
- boolean toggle field with default value = TRUE
- grid view with toggle function on that field


bug:
1) with "edit own" enabled, toggle not working
2) if the above bug is bypassed, toggle function not working, because I get a message DONE but the value is ALWAYS "TRUE", so it doesn't toggle anything.


Bugs reasons and Fixes (backend / frontend):
1) in the toggle function in the controllers file at the line:
		if (!$this->can('core.edit', JText::_("COMPONENTNAME_JTOOLBAR_EDIT")))
			return;

that line should be:
		if (!$this->can(array('core.edit', 'core.edit.own'), JText::_("COMPONENTNAME_JTOOLBAR_EDIT")))
			return;

2) always in the same controller file and in the same function at the line:
		$data["your_toggle_field"] = !$componentitem->your_toggle_field;


that line should be (surely it is not nice looking like the original, but it works with no doubts):
		if ($componentitem->your_toggle_field == 1) {
			$data["your_toggle_field"] = 0;
		} else {
			$data["your_toggle_field"] = 1;
		}

the bug is not fixed yet, we have to go to the TABLE file in the backend at the line:
	/**
	 * @var bool
	 */
	var $your_toggle_field = null;

and replace the value with our default value, in my case TRUE so it will be 1:
	/**
	 * @var bool
	 */
	var $your_toggle_field = 1;


then down to the CHECK function at the line:
		if ($this->your_toggle_field == null)
			$this->your_toggle_field = 1;

we have to delete those two lines that caused the bug.

Moreover, I have noticed sometimes the toggle function in the controllers files, for some weird reason, is not rendered (but in the builder everything is configured correctly), so the workaround to have the toggle function working is to delete from the TABLE in the builder the YOUR_TOGGLE_FIELD and recreate it.

I'm sure the Admin will find a better way to fix these bugs in the builder.
thanks in advance for the support.
Last Edit: 08 May 2012 14:26 by Tomaselli.
The administrator has disabled public write access.
The following user(s) said Thank You: VeCrea

Re: Few things wrong on the TOGGLE feature rendering 10 May 2012 13:49 #2305

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
Many thanks.


Fixed now.

I applied a different code, but yours is working and has been written in correct maneer.

A detail, Cook considers 3 states (TRUE, FALSE, null), so the second part of your code is wrong.
If you want to avoid null value, you only have to specify a default value.
Coding is now a piece of cake
The administrator has disabled public write access.

Re: Few things wrong on the TOGGLE feature rendering 10 May 2012 19:06 #2310

  • Tomaselli
  • Tomaselli's Avatar
  • Offline
  • Elite Member
  • Posts: 293
  • Thank you received: 87
  • Karma: 46
Hi Admin,
thanks for the reply and thanks to have fixed it. but there is still a bug.
you are right there are 3 states, I knew that (in anycase the null state doesn't have any meaning if there is a default value that isn't null). the problem is.....it still doesn't work. Now it has another bug the "0" (FALSE state) is converted to NULL and, due to the following lines, it is consequently converted to TRUE:
		if ($this->your_toggle_field == null)
			$this->your_toggle_field = 1;
removing the above lines is a workaround, the problem is where the FALSE state becomes null (it shouldn't), I don't have time now to see where it happens, tomorrow I'll take a look.
The administrator has disabled public write access.
The following user(s) said Thank You: admin

Re: Few things wrong on the TOGGLE feature rendering 11 May 2012 12:57 #2314

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
Fixed.
if ($this->your_toggle_field === null)   // 3 '=' signs for detecting REAL null value.
	$this->your_toggle_field = 1;
Coding is now a piece of cake
The administrator has disabled public write access.
The following user(s) said Thank You: Tomaselli

Re: Few things wrong on the TOGGLE feature rendering 11 May 2012 13:54 #2315

  • Tomaselli
  • Tomaselli's Avatar
  • Offline
  • Elite Member
  • Posts: 293
  • Thank you received: 87
  • Karma: 46
Thanks!
Surely I will not forget what 3 '=' means :)
The administrator has disabled public write access.
Time to create page: 0.073 seconds

Get Started