by
KK » Sat Sep 14, 2013 9:45 pm
Hello and welcome, skribe

As @lb rightly mentioned above, the noconfict setting allows us to use both jQuery and mootools together. If you need one more example please see
viewtopic.php?f=2&t=4087&p=5333#p5333.
As for the date problem you mentioned -
I agree with you that using the advanced setting dropdown each time for setting a start date can be a chore.
So let us now make it easier

The plan is that we define an editable region (with the datepicker if required) for the start_date too. However, while saving the page,
we insert this editable region's value into the page's publish_date automatically.
This way we get the best of both the worlds - the client can set the date into a normal editable region and we can use the (much more efficient) publish date while listing the events.
This is how we do it -
Please copy and paste the following PHP code in your site's (or the one found in 'couch/addons' folder) kfunctions.php.
- Code: Select all
class MyEvent{
function start_date( $field ){
global $FUNCS;
$start_date = trim($field->get_data());
if( !preg_match('/(?:19|20)\d\d-(?:0[1-9]|1[012])-(?:0[1-9]|[12][0-9]|3[01])/', $start_date ) ){
return KFuncs::raise_error( "Incorrect date format" );
}
// Set publish_date to value of this field
$f = &$field->siblings[3];
$publish_date = trim( $f->get_data() );
if( $publish_date != '0000-00-00 00:00:00' ){
$start_date = $FUNCS->make_date( $start_date );
if( $publish_date != $start_date ){
$f->store_posted_changes( $start_date );
}
}
unset( $f );
return true;
}
}
Then define the editable region for the start_date this way -
- Code: Select all
<cms:editable
name='start_date'
label='Start Date'
desc='Enter date in yyyy-mm-dd format e.g. 2012-12-31'
type='text'
validator='MyEvent::start_date'
separator='#'
validator_msg='myevent::start_date=Incorrect date format'
required='1'
width='155'
/>
Notice how we are associating the PHP code we pasted into kfunctions.php as step one with this editable region via its 'validator' parameter. So each time a page containing this editable region is saved, the validator code kicks in. It validates the date's format
and more importantly also pushes this date into the page's system field that holds the publish_date (this is the one we access using the 'Advanced setting' dropdown).
This saves the client from having to go into the advanced setting.
Hope this helps.
Do let us know.
Thanks.
EDIT:Instead of using a type 'text' editable region, as we did above, we can use a type 'datetime' editable region instead -

- date.jpg (4.12 KiB) Viewed 8242 times
Please see
viewtopic.php?p=25098#p25098 for details.