Problems, need help? Have a tip or advice? Post it here.
14 posts Page 2 of 2
Hi KK,

I did what you sad, but it did not work.

I am getting the following output in my js:
Code: Select all
[2017-06-05 00:00:00],


and I need
Code: Select all
[2017,06,05],
this without the time and the separator must be a comma.

I tried using the separator parameter ( separator=',' ) but did not work etc.

I read in a other topic that it is not possible to change the date format to that what I want except with the date tag https://www.couchcms.com/forum/viewtopic.php?f=2&t=9971&p=23137&hilit=datetime#p23137

This is my code for the admin area
Code: Select all
<cms:repeatable name='booked'>        
        <cms:editable
            name='booked'
            label='booked'
            fields_separator='/'
            type='datetime'
            separator=','
            format='ymd'
            allow_time='0'   
        />




If you have a solution please send me a snippet if not I wil use the text version :)
I used the following definition for the editable region (shows the current date as default - should make it easier to input dates by editing this already inputted value)-
Code: Select all
<cms:repeatable name='booked'>        
    <cms:editable
        name='booked'
        label='Booked'
        type='datetime'
        format='ymd'
        allow_time='0'   
        default_time='@current'
    />
</cms:repeatable>   

And now on the frontend, as I said earlier, we can format the inputted date in any desired pattern as shown below.
For documentation purpose, I'll show examples of both the pattern required by JQuery datepicker and also the 'pickadate.js' you are using.

1. JQuery datepicker


Requires array formatted as follows -
Code: Select all
var booked = ["2017-06-14","2017-06-15","2017-06-18"]

This is how we can do it in Couch -
Code: Select all
var booked = [
<cms:show_repeatable 'booked' >
    "<cms:date booked format='Y-m-d' />"<cms:if k_count!=k_total_records>,</cms:if>
</cms:show_repeatable>
]


2. pickadate.js

Requires array formatted as follows -
Code: Select all
// Array passed in options to disable dates
var datesToDisable = [ [2015,3,8], [2015,3,19]  ]

This is how we can do it in Couch -
Code: Select all
var datesToDisable = [
<cms:show_repeatable 'booked' >
    [<cms:date booked format='Y,n,j' />]<cms:if k_count!=k_total_records>,</cms:if>
</cms:show_repeatable>
]

Notice how we skip the comma for the last value in both samples above.

Please see http://docs.couchcms.com/tags-reference/date.html for the formatting details of dates (e.g. how pickadate.js, as opposed to Jquery, expects days and months without a leading zero).

Hope it helps.
It works KK,

Tnx, only I think jquery datepicker is better because the amsul datepicker is zero indexed so in the admin if I select 01-06-2017 it will be in the front-end 01-07-2017.

NOTE: months in a JavaScript Date object are zero-indexed. Meaning, new Date(2015, 3, 20) is 20 April, 2016.

To stay consistent with this, whenever an integer is used in reference to a month, pickadate treats it as zero-indexed. Dates as strings are still parsed as expected.


But I am happy, thank you very much KK.
Love this CMS
You are welcome :)
14 posts Page 2 of 2