sfirestar
Total posts: 8
05 Jun 2016 15:27

I don't want to choose day, only month and year of the date. How can I do this?

Last Modified: 07 Jun 2016

Tags Useful


pepperstreet VIP
Total posts: 3,837
05 Jun 2016 23:07

Hello sfirestar,
Good point. Funnily I never tried it, until now.

It seems the parameter Custom picker format is used to display the already chosen date on the form.
It is not the format you see during selection with one of the input-templates.
I mean, it has no impact on the input style. For instance: picker does still display the full calendar style; simple-select does still display all 3 selects (+ optional time)

I wonder why this parameter can't be used to create a custom "input mask"?
Also the info tooltip does state it would not work with text-input :(


Some ideas and suggestions

A.) Copy/modify one of the input-templates...
Simple-Select would be the easiest. Although, I am not sure if a removed days-select needs a default value for correct storage? I have tested with default "days" which is the value 0, but then it stores with the last day of the previous month!? (bug or on purpose?)
Text-Input would require the mentioned "mask".
Calendar/Picker would need to skip/ommit the days display. It should start with the month display only.

B.) use CSS to hide days
Applies to Simple-Select template only.
One of the following three CSS rules should work:

/* DATE & TIME hide first/day select element  */

/* By FIELD ID# */
/* replace 99 with your field ID */
#fld-99 select[name$="[day]"] {
    display: none;    
}


/* By FIELD ID# and first-of-type */
/* replace 99 with your field ID */
#fld-99 select:first-of-type {
    display: none;    
}


/* By CUSTOM FIELD CLASS and first-of-type */
/* class can be set in field parameters */
.MYCLASS select:first-of-type {
    display: none;    
}

pepperstreet VIP
Total posts: 3,837
06 Jun 2016 00:00

pepperstreet A.) Copy/modify one of the input-templates... Calendar/Picker would need to skip/ommit the days display. It should start with the month display only.

Picker/Calendar months and year only

Here is a slightly modified field input-template, which starts with "months" ;)
Still using 2 columns, could be changed to 1 or more as well.

Download attachment:
single_date_picker_months.php

UNZIP and put template here:
/YourJoomla/components/com_cobalt/fields/datetime/tmpl/input/...

Set template and save field:
cob_datetime_input_template

Frontend form and calendar should look like this:
cob_datetime_picker_months_frontend

Set output parameters accordingly...
Hope this helps.


Jeff VIP
Total posts: 745
06 Jun 2016 01:44

I'm curious, if you only select month and year what date is actually saved in the database?


pepperstreet VIP
Total posts: 3,837
06 Jun 2016 03:11

Jeff I'm curious, if you only select month and year what date is actually saved in the database?

Yep, that was my first thought, too ;)

The current MooTools(!) powered Picker/Calendar seems to use the current date for the initial calendar display.
So for today, it starts with highlighted month "June" and sets also the day to 6th. (Although, parameter Inputs default value was set to Nothing. It has no impact)

The Simple-Select has a strange behavior. I have tested with default "days" which represents the value 0, but then it stores with the 30th or 31th of the previous month!? (a bug or on purpose?)
As far as I can see, there is no special validation.


Jeff VIP
Total posts: 745
07 Jun 2016 01:35

pepperstreet The current MooTools(!) powered Picker/Calendar seems to use the current date for the initial calendar display.

I have abandoned the Picker/Calendar because of it's Mootools dependency, the many other scripts it loads and the non responsive design. It should definitely be replaced in the next major version of Cobalt with a lightweight modern jQuery version.

pepperstreet As far as I can see, there is no special validation.

A while ago I tried to select only year, which of course didn't work. Another issue was that I wasn't able to filter just by year or month, without going through an exessive number of clicks. I have made a workaround by saving months and years as seperate fields.

Working with dates is like alchemy, simple questions often lead to complicated solutions...a little bit of magic may be needed....

Try this:

  • Show records that happended on a Monday
  • Show records that occurred on a November
  • Show records that happend on the 7th day of the month
  • Show records of people who are 65 years old
Powered by Cobalt