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

Question

Question

.change() in Modern Designer

asked on August 13, 2024 Show version history

We have some field formulas that aren't being triggered if the field is populated when the form is loaded.
 

In the Classic Designer, we got around this by adding a JS line with .change() at the end (this works perfectly).
 

How can this be accomplished in the Modern Designer? 

We tried LFForm.setFieldValues, but see that won't work for Collections or Read-Only fields (our current need involves both).
 

Has anyone found a workaround for this issue?

 

Edit to add that this seems to be similar to this recent post by Blake Smith:
https://answers.laserfiche.com/questions/221776/ReadOnly-Field-Populated-by-Calculation-Not-Saving-Value

We are on version 11.0.2311.50556

setFieldValues.JPG
1 0

Answer

SELECTED ANSWER
replied on August 14, 2024

This is the code that ended up working for us. It did not work if the collection was read-only, so we ended up making it "Disabled" using Field Rules, and that did work (it looks the same as read-only, so the end users won't notice a difference. Huge thank you to @████████!!!

function resetFunctionFields(resetFieldID) {
  let resetFields;
  let currIndex = 0;
  let currOldValue;
  
  resetFields = LFForm.findFieldsByFieldId(resetFieldID); 
  
  /* loop through all fields */
  resetFields.forEach(async function (currField) {
    currOldValue = LFForm.getFieldValues(currField);

      LFForm.setFieldValues({fieldId: resetFieldID, index: currIndex}, currOldValue)

    currIndex++; 
  }); 

}; 

/* on load */
resetFunctionFields(97);  //this is the field ID  

 

2 0

Replies

replied on August 13, 2024

I mocked up some code based on the example Zachary gave in the post https://answers.laserfiche.com/questions/221776/ReadOnly-Field-Populated-by-Calculation-Not-Saving-Value  and some code I have used for looping through a set of fields in a collection/table. I have not tested it but it may work with tables or collections.

 

const resetField1ID = 2;
const resetField2ID = 3;

function resetFunctionFields(resetFieldID) {
  let resetFields;
  let currIndex = 0;
  let currOldValue;
  
  resetFields = LFForm.findFieldsByFieldId(resetFieldID); 
  
  /* loop through all fields */
  resetFields.forEach(async function (currField) {
    currOldValue = LFForm.getFieldValues(currField);
    
    LFForm.setFieldValues({fieldId: resetFieldID, index: currIndex}, "")
      .then(() => {
      LFForm.setFieldValues({fieldId: resetFieldID, index: currIndex}, currOldValue)
    });
    
    currIndex++; 
  }); 

};

/* on load */
resetFunctionFields(resetField1ID);  
resetFunctionFields(resetField2ID);  

 

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

Sign in to reply to this post.