Date range day

leblancphil

Member
Hello happy Fabrik super users

I m poor with javascript and I would like to do this :

In my form I have a databasejoin field with day choice like monday = 1 thuesday = 2 ect....
In the same form I have a date field and I need the choice of dates to be limited to the day chosen before
exemple : if I select monday I can only select mondays in my date picker.
Thanks for your attention.
 
The wiki page for the Date element has a section on Advanced functionality which shows how to decide which dates to allow. Obviously you are looking to get the weekday value (0-6) of the date you are checking and compare it to a slightly different value (1-7) for the dropdown. So there are few things you need to do:
  1. Get the value of the dropdown:
    Code:
    var dayofweek = document.getElementById('mytable__dbjoin').value;
    where 'mytable__dbjoin' is your table name and the element name for the databasejoin.
  2. If this is empty (no weekday has been selected in the dropdown) then you probably want to return true or false regardless.
  3. Get the day of the week for the variable 'date' using the javascript Date object method to get the day of the week.
  4. Convert the dropdown value (1-7) where 1 is a Monday to (0-6) where these are defined by the above javascript function. So you may need to add an offset and then take the result modulo 7 to make this the same.
  5. Compare the two and set the return variable to true if they are different and false if they are the same.
All the pieces you need to make this work are defined above. I am leaving putting it together as a learning exercise for you.

If you get stuck, come back with your best shot and I will help you further.

If you make it work, please add it as an example in the wiki page.
 
We are in need of some funding.
More details.

Thank you.

Staff online

Members online

Back
Top