-
-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A new version is saved even though no changes have been made #26
Comments
|
In my extension I found a (not perfect) solution where I wanted to have a separate input of date and time: I simply added a load and save callback and adjusted the timestamp to match the expected values. (see also https://github.com/agoat/contao-postsnpages-bundle/blob/master/src/Resources/contao/dca/tl_posts.php#L238-L274) // Fields
'fields' => array
(
'date' => array
(
// ..
'load_callback' => array
(
array('class', 'loadDate')
),
'save_callback' => array
(
array('class', 'resetTime')
),
// ..
'time' => array
(
// ..
'load_callback' => array
(
array('class', 'loadDate')
),
'save_callback' => array
(
array('class', 'resetTime')
),
// ..
// ..
/**
* Reduce the tstamp to contain only the date tstamp
*
* @param integer $value
*
* @return integer
*/
public function loadDate($value)
{
$objDate = new \Date(date('Y-m-d', $value), 'Y-m-d');
return $objDate->tstamp;
}
/**
* Reduce the tstamp to contain only the time tstamp
*
* @param integer $value
*
* @return integer
*/
public function loadTime($value)
{
$objDate = new \Date(date('H:i:s', $value), 'H:i:s');
return $objDate->tstamp;
}
/**
* Reset the date and/or time to the current time if empty
*
* @param integer $value
*
* @return integer
*/
public function resetTime($value)
{
return empty($value) ? time() : $value;
}
``` |
|
@agoat this way you have to use two separate variables in order to display the date and time in the front end. |
|
No. The |
|
Ah, I see. |
|
Fixed in 440e9f2. |
|
@agoat I didn't see your solution until right now. I will give it a try. |
|
I have implemented your solution in e591ee4. |
I noticed that every time you save, a new version is created, although it hasn't been changed.
It looks like the adjustTime callback handling the date and time input is causing this behaviour.
When the form is submitted, the dc_table driver will first save the timestamps for each of these fields and the onsubmit_callback will add the two timestamp together and saves them again.
This result in an always different timestamp when loading the form and when saving (e.g. the time input only return and save the seconds from midnight to the entered hours and minutes).
This is the same in the calendar-bundle when time is added.
I don't know a solution right now. One solution could be to use a single field with 'regx'=>'datim'. But that is not user friendly when time is not relevant.
The text was updated successfully, but these errors were encountered: