Welcome, Guest
Username: Password: Remember me

TOPIC: Form calendar NULL value

Form calendar NULL value 18 Jun 2019 13:28 #15740

  • liubov
  • liubov's Avatar
  • Offline
  • Elite Member
  • (=) 10 mn and it's ready!
  • Posts: 278
  • Thank you received: 35
  • Karma: 22
Hello J-Cookers,
I have a Calendar to set Date into a Item Form.
For the first time, I tried to remove (clear) the date and save. But the reccord still come back. Checked also with the Builder, same behaviour.

I think something is missing in the code to push the NULL value in the date field.

An idea ?
Marc.
The administrator has disabled public write access.

Form calendar NULL value 23 Jun 2019 17:12 #15741

  • vlemos
  • vlemos's Avatar
  • Online
  • Elite Member
  • Posts: 295
  • Thank you received: 41
  • Karma: 21
You can reset date to 0000-00-00 00:00:00 if nothing else works
The administrator has disabled public write access.

Form calendar NULL value 24 Jun 2019 17:08 #15743

  • liubov
  • liubov's Avatar
  • Offline
  • Elite Member
  • (=) 10 mn and it's ready!
  • Posts: 278
  • Thank you received: 35
  • Karma: 22
thank vlemos,
the probleme is that I set 'NULL' as default value in order to test if there is a reccorded date in the field.
So I try to do the same thing that content Item (publish_out) ...
The administrator has disabled public write access.

Form calendar NULL value 09 Jul 2019 08:47 #15744

  • Romkabouter
  • Romkabouter's Avatar
  • Offline
  • Elite Member
  • Posts: 310
  • Thank you received: 131
  • Karma: 48
Hi there,

I have had the same issue and finally dug into it and solved the issue.
The problem lies in the fact that a Joomla Table has an method "store". That has an argument called "$updateNullValues"
By default, this argument is never used.
Also, the method "bind" ignores values which have a NULL value.
Effectively, this leads to NULL values not being updated at all

To be able to clear the datetime field (aka set is to NULL), you have to:
  • Fork the table
  • Override bind() and store()

I have forked my class table (file is fork/tables/class.php), you can start with making a copy of the table you need to override from "_fork" folder, either in administrator or site root, depending on your need.
Met code inside my forked class.php:
class ShowmanagerTableClass extends ShowmanagerCkTableClass
{
    public function store($updateNulls = true) {
        //updateNull will be true if not set, resulting in Joomla updating NULL values as well.
        //Call parent 
        return parent::store($updateNulls);
    }

    public function bind($src, $ignore = array())
	{
          $result =  parent::bind($src, $ignore);
          //override to allow NULL in time fields
          foreach ($this->getProperties() as $k => $v)
          {
              // Only process fields not in the ignore array.
              if (!in_array($k, $ignore))
              {
                 //you can remove the whole if statement as well, or explicitly list the fields needed
                  if (isset($src[$k]) || $k == 'time_per_contestant' || $k == 'time_per_class' || $k == 'time_ceremony_per_contestant')
                  {
                      $this->$k = $src[$k];
                  }
              }
          }
         return $result;
    }
}

Hope it helps!
The administrator has disabled public write access.
The following user(s) said Thank You: admin, liubov, vlemos

Form calendar NULL value 09 Jul 2019 11:21 #15747

  • liubov
  • liubov's Avatar
  • Offline
  • Elite Member
  • (=) 10 mn and it's ready!
  • Posts: 278
  • Thank you received: 35
  • Karma: 22
Yeah, thank you.
It works like a charm :p
I had also 3 Date Field to manage my Breeding Plan ...
Good job ! I think this over class could be add in the next Builder, when choosing 'NULL' as Default value.

Marc
Last Edit: 09 Jul 2019 11:54 by liubov.
The administrator has disabled public write access.

Form calendar NULL value 09 Jul 2019 11:54 #15748

  • liubov
  • liubov's Avatar
  • Offline
  • Elite Member
  • (=) 10 mn and it's ready!
  • Posts: 278
  • Thank you received: 35
  • Karma: 22
/**
* Jbreeding Table class
*
* @package	Jbreeding
* @subpackage	
*/
class JbreedingClassTable extends JTable

{
    public function store($updateNulls = true) {
        //updateNull will be true if not set, resulting in Joomla updating NULL values as well.
        //Call parent 
        return parent::store($updateNulls);
    }

    public function bind($src, $ignore = array())
	{
          $result =  parent::bind($src, $ignore);
          //override to allow NULL in time fields
          foreach ($this->getProperties() as $k => $v)
          {
              // Only process fields not in the ignore array.
              if (!in_array($k, $ignore))
              {
                 //you can remove the whole if statement as well, or explicitly list the fields needed
                  if (isset($src[$k]) || $k == 'forcasted' || $k == 'awaited' || $k == 'birthday')
                  {
                      $this->$k = $src[$k];
                  }
              }
          }
         return $result;
    }
}
The administrator has disabled public write access.

Form calendar NULL value 09 Jul 2019 12:10 #15749

  • Romkabouter
  • Romkabouter's Avatar
  • Offline
  • Elite Member
  • Posts: 310
  • Thank you received: 131
  • Karma: 48
I do not think that is correct, what is the tablename you want to fork?
Look at my class header:
class ShowmanagerTableClass extends ShowmanagerCkTableClass

In my case, the tablename is Class, my component is called Showmanager
In your case is works, becauase you now override every table, which might not be what you want.
Last Edit: 09 Jul 2019 12:13 by Romkabouter.
The administrator has disabled public write access.
The following user(s) said Thank You: admin, liubov

Form calendar NULL value 09 Jul 2019 16:18 #15750

  • liubov
  • liubov's Avatar
  • Offline
  • Elite Member
  • (=) 10 mn and it's ready!
  • Posts: 278
  • Thank you received: 35
  • Karma: 22
Ok I see...

From the beginning, I 've never used the Fork system. I have to many custom code everywhere to manage this. When the Builder update code I compare the new source with previous source and make the updates manualy. Less code and more simple in my mind.

But you mean if I do not use Fork I can not override class.php for a specific Table ?
My table name is Portee (Litter in english), and the 3 fields are 'forcasted', 'awaited' and 'birthday'

An idea ?
The administrator has disabled public write access.

Form calendar NULL value 09 Jul 2019 16:50 #15751

  • liubov
  • liubov's Avatar
  • Offline
  • Elite Member
  • (=) 10 mn and it's ready!
  • Posts: 278
  • Thank you received: 35
  • Karma: 22
Ok, I got it.

Just move the bind() and store() function in the good table.
// /admin/tables/portee.php
/**
* Jbreeding Table class
*
* @package	Jbreeding
* @subpackage	Portee
*/
class JbreedingTablePortee extends JbreedingClassTable
{

and it still works :p

Thanks a lot.
The administrator has disabled public write access.

Form calendar NULL value 09 Jul 2019 17:11 #15752

  • Romkabouter
  • Romkabouter's Avatar
  • Offline
  • Elite Member
  • Posts: 310
  • Thank you received: 131
  • Karma: 48
Yes indeed, but if it works for you and don't break other tables, you're ok with whatever you create :)
I have a lot of forked code and keep it separate, I have a script to create a package so that I can install a new version.
Your way of working is fine as well, but I feel that might be more work with every new version.
The administrator has disabled public write access.

Form calendar NULL value 09 Jul 2019 19:46 #15753

  • liubov
  • liubov's Avatar
  • Offline
  • Elite Member
  • (=) 10 mn and it's ready!
  • Posts: 278
  • Thank you received: 35
  • Karma: 22
Really appreciate your point of vue.

I started the job like you when fork system appeared, but after a time and few updated versions, I realized that almost all the files were customized. Since 1.5, j-cook core has often changed, and I had to review a lot of Fork files to be compatible with new Classes, new Method, new Object, etc ... Meaning also that in Package, you find the native source code AND the full Fork code, real engine that run your Component.
Considering that each Builder update affects (sometimes) a small part of the files, I thought it's was a good thing to find, check and paste the code directly in my package, increasing the version.
Linux Kompare engine do make the rest :P

PS: Sorry for Nederland Football Girl who didn't catch the Cup
The administrator has disabled public write access.

Form calendar NULL value 09 Jul 2019 19:51 #15754

  • Romkabouter
  • Romkabouter's Avatar
  • Offline
  • Elite Member
  • Posts: 310
  • Thank you received: 131
  • Karma: 48
I don't follow football at all, but thanks anyway :D
As you can see in my profile picture I am more into horseback riding.

Glad I could help!
The administrator has disabled public write access.

Form calendar NULL value 15 Jul 2019 09:29 #15756

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 984
  • Karma: 140
Thank you guys, that's a good one.

I also noticed a formating issue in the calendar picker since PHP 5.3
Gonna fix all this soon
Coding is now a piece of cake
The administrator has disabled public write access.

Form calendar NULL value 18 Jul 2019 01:04 #15758

  • vlemos
  • vlemos's Avatar
  • Online
  • Elite Member
  • Posts: 295
  • Thank you received: 41
  • Karma: 21
Nice

k++
The administrator has disabled public write access.
Time to create page: 0.241 seconds

Get Started