You are viewing limited content. For full access, please sign in.

Question

Question

Range of Dates in Row Labels

asked on March 31, 2020

I am building an online timesheet. 

In the paper version, the user needs to write in the date for each row (clearly less than ideal). 

In Laserfiche Forms, I would like to have the user enter the first date of the pay period (in a Date field), then have the row labels populate automatically with the dates of the pay period. 

I don't know Javascript, but I've done a lot of searching in this forum and have made some progress. Where I'm stuck is getting the date to increment. Taking a date of 3/31/2020 and adding one returns 3/31/20201.  I think maybe I need to convert back into a date format?  I've tried a variety of things without success, and the addDays function in Javascript doesn't seem to work at all. I also don't need the hours, minutes, and seconds, just the day, month, year.

Here's what I have so far; can someone please help?

/* Date Range in Row Labels */
$(document).ready(function () {
      $(".startdate input").change(function(){
         setDateRange();
    });
      
      function setDateRange(){

        var startdate=$('.startdate input').val();
        var parent = document.getElementById('q115');
        var label = parent.getElementsByClassName('col0');

        var day1 = startdate;
        var day2 = startdate + 1;
        
        label[0].innerHTML = day1
        label[1].innerHTML = day2
      }
    });

day1 returns correctly

day2 just returns day1 with the number 1 appended to the end

 

Thanks in advance!

0 0

Answer

SELECTED ANSWER
replied on April 1, 2020 Show version history

Hi Jennifer

This can be done just using Formula's as I've done this myself. Add a number field to your table, I named it ROWID (you can hide this with rule when done), and enter the formula =ROW() in the Advanced Tab. What this will do is to number your fields from 1 to whatever. In my case a pay period is 14 days so I set the Table to a fixed number of 14, which always shows 14 days, In the Day field in the table (date field), I calculate the daily date with

=SUM(Pay Period Start Date,INDEX(tablename.Day.ROWID,ROW()))

See note following

You need to use the right variable but what this does is adds the ROWID value (1 to 14) to the appropriate day field to increment the date.

What I have also done is to use some JS with the PayPeriod DatePicker field to limit the day to be selected to only Sunday (for me this is the first day of any pay period). 

2 0
replied on April 1, 2020 Show version history

Hi Jennifer

I forgot I had to account for the First Row being Row 1 and not 0, So, I also had to subtract 1 from the Row number so the first Date was the first date picked. Could also have subtracted 1 from the Picked Date and then added the Row number, which would also work. My Formula

=SUM(PayPeriodFrom,SUB(INDEX(TimeSheetTable.ROWID,ROW()),1))

The alternate would have looked like

=SUM(SUB(PayPeriodFrom,1),INDEX(TimeSheetTable.ROWID,ROW()))

 

0 0

Replies

replied on April 1, 2020

Make DatePicker only have selectable Sunday dates. in the code t==0 represents Sunday, Monday is 1, etc

$(document).ready(function(){
  function isCorrectDate(n) {
    var t = n.getDay();
    var d = n.getDate();
    return (t==0);
  }
  function checkDate(n) {
    return[isCorrectDate(n),""];
  }
  function checkField(input, inst) {
    if ($(input).closest('li').hasClass('myDate')) {
      $(input).datepicker("option", {beforeShowDay: checkDate});
    }
  }
  $.datepicker.setDefaults( {beforeShow: checkField} );
  window.Parsley.addValidator('secondsat', {
    validateString: function(value) {
      return isCorrectDate(new Date(value));
    },
    messages: {
      en: 'Not valid date.'
    }
  });
  $('.myDate input').attr('data-parsley-secondsat','');

 });

2 0
replied on April 1, 2020

This all worked perfectly - I can't thank you enough!  smiley

0 0
replied on February 8, 2024

@████████ ever do this kinda thing in javaScript in the new designer?

0 0
replied on February 8, 2024

Hi Chris, I haven't attempted to restrict the dates in the new designer, yet...
Will let you know if I come across anything

1 0
replied on April 1, 2020

Thank you so much, Steve!

The first day of our pay period is also Sunday; could you please also share that code?

0 0
replied on April 1, 2020

As an FYI, my form looks like this

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.