How to set date element to specific date?

Status
Not open for further replies.

JennaMar

Member
Hi community,
trying to set the calendar to a specific date and need your help. So, that it is starting with octobre.
Tried with setDate and moveTo but don't understand how the result should look like.
Sorry for this bad explanation, hope you can understand it.
Thanks a lot
J
 
An example of what i am trying to do

var d = defaultDate('2016-10-1);

but now, there has to be a result,right?

var result = ???
 
Last edited:
If you want to set a default date use the Default setting.
e.g. 2016-10-01
The date picker will open with this month, too.
 
Ok, this will work for the required field, but i also have 2 optional datepicker, they have to be blank
 
The only way you could do that would be in JavaScript. I've added two new Fabrik events, fired when the calendar is created, and when it is opened. You only need the 'created' one, I just added 'opened' for fun.

https://github.com/Fabrik/fabrik/commit/f8d126e452930708ecddd77d8e25a3aa4abccb40

So, after doing a github update, you should now be able to set the calendar date when it is created, without setting the date element's date. What normally happens is we take whatever date the element has, and set the calendar widget to that, or if it isn't set, use todays date. You should now be able to reset the date the calendar is set to when we create the calendar object, by using a form_X.js file (in ./components/com_fabrik/js, replace X with the numeric form ID), and code like this:

Code:
requirejs(['fab/fabrik'], function () {
   Fabrik.addEvent('fabrik.element.date.calendar.created', function (el) {
      // check to see if this is one of the dates we need to set
      if (el.strElement == 'yourtable___date1' || el.strElement == 'yourtable___date2') {
         // cal the date picker widget's setDate function
         el.cal.setDate(new Date('2016-10-01'));
   }
}

Substitute your element names, and the date you need.

-- hugh
 
May be some brackets missing?
saved this under form_1.js in components/com_fabrik/js

bracket after requirejs and after function() and after Fabrik.addEvent i tried to close, but doesn't work
 
requirejs(['fab/fabrik'], function () {
Fabrik.addEvent('fabrik.element.date.calendar.created', function (el) {
if (el.strElement == 'formular___kalender') {
el.cal.setDate(new Date('2016-10-01'));
}
})
})

This works in my example site
Thank you
 
Successfully solved :)
All datepickers show new date
What i have not understood is, if there will be a fix for date element delivering todays date in receipt ( a thread i opened )? Anyway, great job
 
Status
Not open for further replies.
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top