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

Question

Question

Can I populate the label of a number field with the value from another field?

asked on August 7, 2024 Show version history

Hello, I am trying to build a timesheet on Laserfiche forms for my organization, however, am running across an issue getting the calculated dates (based on the date input by user in the Pay Period Start Date field) to populate the labels of the corresponding date fields. The calculated date fields will be hidden on the final product (visible here for reference).

I am using the Layout Designer on Laserfiche Forms Professional Version 11.0.0.537.

Here is a sample mockup of the form. Is this even possible?

 

 

0 0

Replies

replied on August 7, 2024 Show version history

EDIT: As Mattthew pointed out, the following requires a more recent version of Forms. In version 11.0.0.537 it would require the Classic Designer and a different approach.

 

You can do it with JavaScript and the LFForm object.

The trick is to use the change event on a field, followed by a formatting method to format it how you want, and lastly the changeFieldSettings method to update the label.

You would need to update this with your corresponding field ids. You could probably bypass those extra fields entirely and just increment the date for each column.

Alternatively, you could attach a handler for each of your wk1_date1, wk1_date2, etc. fields, but that is a bit more complicated because you'd need more handlers; if you tie it all to the single date and just increment the date in JavaScript you can cut it down to one method that updates them all in one go, but it depends on what works best with your process.

You'll need more than this to finish what you're doing, but these are the main the pieces you'll need.

const dateField = { fieldId: 20 };
const columnField = { fieldId: 13 };

LFForm.onFieldChange(function(){
  let newLabel = '';
  let dateValue = LFForm.getFieldValues(dateField);
  
  if (dateValue?.dateTimeObj != null) {
    newLabel = getFormattedDate(dateValue.dateTimeObj);
  }
  
  LFForm.changeFieldSettings(columnField, { label: newLabel })
}, dateField);

function getFormattedDate(dateStr) {
  var date = new Date(dateStr);
  var year = date.getFullYear();
  var month = (1 + date.getMonth()).toString();
  month = month.length > 1 ? month : '0' + month;

  var day = date.getDate().toString();
  day = day.length > 1 ? day : '0' + day;
  
  return month + '/' + day + '/' + year;
}

To increment date in a way that accounts for auto-incrementing month when necessary

date.setDate(date.getDate() + 1);

For reference, on my test form the standalone field 20 referenced in the code above is the standalone Date Time and field 13 is the column getting the label change; these values should be displayed when you open the JavaScript tab in the forms layout designer.

3 0
replied on August 8, 2024 Show version history

@████████ - you will need to upgrade LFForms before being able to utilize @████████'s solution.  And it is a great solution.  You mentioned you are on Version 11.0.0.537, which is a very early release of Forms 11.  Javascript functionality in the Modern Designer wasn't added until Forms 11 Update 3 (version 11.0.2212) and I believe the LFForm.changeFieldSettings function may not have been added until a later version than that. 

The current release is Forms 11 Update 5 (11.0.2311) and I strongly recommend upgrading if you can, as the functionality within the Modern Designer has very drastically improved since the initial release, not only gaining Javascript functionality such as this, but other very powerful improvements to things like Field Rules.

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

Sign in to reply to this post.