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

Question

Question

Collections and LF 11

asked on June 26

Hi,

Can anyone tell me if this is possible?  I'm in LF11.  a user enters a number in a single line field and the collection makes that many collections as in a user enters 5 in a field and this happens automagically without the user clicking the "+ Add" button 4 times.  The number could possibly be up to 250 kits:

I believe the JS would have to be vanilla JS and I'm not familiar with that.

Any help would be appreciated

0 0

Replies

replied on June 26

It's possible with tables, I would imagine it's possible with collections as well with some modifications. 

Apologies, I don't have time to rework my code to make it work for collections, but here's the Javascript I'm using to change the number of rows in a table based on the value entered in another field:

// Allocate Blocked Tickets Section Populate Table Rows
const updateTable1Rows = async (tableFieldId, rowCount) => {
  const currentTable1FieldValues = LFForm.getFieldValues(tableFieldId);
  const curRowCount1 = currentTable1FieldValues.length;

  if (curRowCount1 < rowCount) {
    await LFForm.addRow(tableFieldId, rowCount - curRowCount1);
  } else if (curRowCount1 > rowCount) {
    await LFForm.deleteRow(
      tableFieldId,
      ...Array.from(Array(curRowCount1 - rowCount)).map(
        (_, i) => curRowCount1 - i - 1
      )
    );
  }
};

let lastFieldValue1 = null;

LFForm.onFieldChange(
  async () => {
    const fieldValues1 = LFForm.getFieldValues({ fieldId: 56 });

    // Check if the field value has changed since the last time a row was added
    if (fieldValues1[0] !== lastFieldValue1) {
      // Update the table rows with the new row count
      await updateTable1Rows({ variableName: 'FT_Allocate_Passengers' }, fieldValues1);
      lastFieldValue1 = fieldValues1; // Update the last field value
    }
  },
  { fieldId: 56 }
);

Hopefully it gives you a head start, or someone else can chime in and make the necessary adjustments for you.

Also just to add - I'm using the modern designer in Cloud, so there might need to be extra modifications due to that, although I'm not sure if that's the case or not.

Good luck!

2 0
replied on June 26

Sarah,

Thanks for the effort but I am not experienced enough to turn that into a collection script.

0 0
replied on June 26

That code (I mostly wrote, love to see you use it!) will work with tables and collections. Just make sure the fieldIds reference the fields you need

2 0
replied on June 26

It's been so incredibly helpful, thank you for writing it! :)

We use it for booking/allocating flights for seasonal staff, up to 50 at a time. So it saves a TON of clicking haha

Good to know it will work for collections as well!

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

Sign in to reply to this post.