Coded something up in Couch in an interesting way? Have a snippet or shortcode to share? Post it here for the community to benefit.
5 posts Page 1 of 1
I understand from other posts in the forum that while using and editable field for an event start date is not ideal, but that it is possible.

My client would rather not have to go to advanced settings each time. (Their adding a lot of dates) How would one go about doing this, so that it works with the calendar entries tag?

Also in the course of trying a work around for this I found that jquery in a template <cms: editable> field with the message type is not agreeable to the admin panel. Is this right?

For the jquery part try putting this into a type message:

Code: Select all
<script src="//"></script>
(function($) {
    //use '$' as you normally would
    $(document).ready(function() {


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
    label='Start Date'
    desc='Enter date in yyyy-mm-dd format e.g. 2012-12-31'
    validator_msg='myevent::start_date=Incorrect date format'

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.


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 646 times

Please see viewtopic.php?p=25098#p25098 for details.
Great! Thank you both for the solutions. I had not run across the kfunctions file yet. I will make use of that in the future for sure! I have never really use moo tools before, and was not aware there was a conflict between the two.

Coming from years of working with Wordpress, Couch is a breath of fresh air for small sites! Yet I can't believe how powerful it is.
I added the code to my kfunctions file & template, and it worked first crack out of the box. :) Thanks again! Perhaps a link should be added to this from the tips and tricks section?
5 posts Page 1 of 1

Who is online

In total there is 1 user online :: 0 registered, 0 hidden and 1 guest
(based on users active over the past 5 minutes)

Users browsing this forum: No registered users and 1 guest