Skip to content
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

Closed
agoat opened this issue Nov 13, 2017 · 7 comments
Closed

A new version is saved even though no changes have been made #26

agoat opened this issue Nov 13, 2017 · 7 comments
Assignees
Labels
Milestone

Comments

@agoat
Copy link
Contributor

agoat commented Nov 13, 2017

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.

@agoat agoat changed the title A new version is always saved, although there is no change A new version is saved even though no changes have been made Nov 13, 2017
@leofeyer leofeyer added this to the 4.4.9 milestone Nov 20, 2017
@leofeyer leofeyer self-assigned this Dec 5, 2017
@leofeyer leofeyer closed this as completed Dec 5, 2017
@leofeyer leofeyer reopened this Dec 5, 2017
@agoat
Copy link
Contributor Author

agoat commented Dec 5, 2017

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;
	}

	```

@fritzmg
Copy link
Contributor

fritzmg commented Dec 5, 2017

@agoat this way you have to use two separate variables in order to display the date and time in the front end.

@agoat
Copy link
Contributor Author

agoat commented Dec 5, 2017

No. The onsubmit_callback is still present and adjusts both fields.

@fritzmg
Copy link
Contributor

fritzmg commented Dec 5, 2017

Ah, I see.

@leofeyer
Copy link
Member

leofeyer commented Dec 5, 2017

Fixed in 440e9f2.

@leofeyer leofeyer closed this as completed Dec 5, 2017
@leofeyer
Copy link
Member

leofeyer commented Dec 5, 2017

@agoat I didn't see your solution until right now. I will give it a try.

@leofeyer
Copy link
Member

leofeyer commented Dec 5, 2017

I have implemented your solution in e591ee4.

@leofeyer leofeyer closed this as completed Dec 5, 2017
@leofeyer leofeyer modified the milestones: 4.4.9, 4.4 May 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants