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

Question

Question

Modal Window Questions - capture text? in a table?

asked on July 7 Show version history

Using: LF Forms 11 Update 5, Modern Designer, self-hosted

I've been wrestling with the JS that @████████ shared with us at Empower2025 in the Advanced JS course. I have a couple questions about that.


I can get the modal window to open and blur the background. It's just so cool ha ha. I am trying to get a text field in the modal window to populate a hidden field. Is this even possible? I can get the textarea to show in the modal window, but can't capture the text in it. Any suggestions on how to do that? It all exists in the temporary html of the modal window so the LFForm functions are not effective. 

I have tried the section method as well, but let me share where I am trying to get to with this. I have a very busy dynamic timesheet that can vary the number of columns. Some users will have a very little space available on the table. Stakeholders now require a comment field per day. I thought of the modal window as a great way to capture a comment and only require space for a small button in the table. 

Is it even possible to have a modal window per row of a table? I have thrown several hours trying to capture the index of the button onClick to no avail. 

So here I am asking the community for a hand :)

Cheers friends, and thanks in advance as always. 

0 0

Replies

replied on July 7

Glad to hear you're using my modal component! You can definitely accomplish what you need with the section modal. Here's what you would do:

  1. add a section outside of the table with the fields you want to include in the modal
  2. add the lf-modal class required to the section
  3. in JS initialize the modal on the section by field id
  4. put an "Add comment" button in each row 
    1. in JS define a function on the window "window.openModal = . . ." that shows the modal with modal.show()
    2. in the button custom html add the "onclick=openModal()"
  5. At this point testing the form should show the modal when you click the "Add comment" button and hides when you click "ok" in the modal
  6. The tricky part is determining the row number of the button being clicked. The easiest way to do this is to listen to an onchange event on any column of the table and recreate the button with JS to pass the row number in the "onclick=openModal(1)"
  7. now in your openModal function you can take the row number and use the LFForm object to copy any values you need to the section modal
  8. Now all that is left is the inverse, register an on close event that takes the values from the section and copies it back to the row of the table that opened the modal
1 0
replied on July 10 Show version history

Type: section approach
I am using Forms 11 Update 5, so this may not be an issue in 12? 

Regarding the 'section' approach, the modal window does not 'pop out' unless I apply the correct modal css to the fl-section or pane element within the section. When i do this manually, it looks great. Applying the class to the section itself does not create the modal window. (applying the backdrop class to the section DOES darken and blur correctly)



Asking AI about it, it gave me this info which may or may not be accurate lol


Regardless, this is the roadblock I hit using the 'section' approach. Any guidance on that? If upgrading to 12 is what it takes, I am game. Well, it would add additional pressure to our timeline to do that sooner than later. 

Thanks so much.

0 0
replied on July 21 Show version history

I am going to assume Modal functionality isn't possible in 11. It is almost possible but can't get the last piece of it (both methods). 

I ended up using a 'pseudo-modal' solution using (vanilla) JavaScript to show and hide everything except a section I formatted to look modal. Then the JS takes the text and enters it onto the row that kicks off the change. It's working great. I hunted for a way to return focus to an area of a form. That is the only glitchy part about this solution. The user needs to scroll back to where they were. I didn't find anything compatible with 11. Anyone else out there have any luck with returning focus in 11?

We are prepping to upgrade our LFDS to 12 as the first step of our  'twelve-ification' of all the other apps. So, I hope to test the modal functions again soon :)

I'm happy to share my JS to identify the index of a row and the 'pseudo-modal' show/hide & populate fields. 

Cheers friends!
 

0 0
replied on July 8

Thanks so much! I'm working through all this. First change was to use a checkbox instead of a button to detect the onChange event. I am successfully getting the index! I'm just wiring in the other details now. 

0 0
replied on July 9

awesome! the row index is the hardest part of the script. If you need any more help let me know!

0 0
replied on July 9 Show version history

Type: customHTML approach

Ok, I hit a roadblock. I have tried the section and the customHTML field options. Right now I have js inject a blank customHTML field with my text field and buttons. The modal window loads, I can enter text and can 'close' but nor 'save & close' because the textarea cannot be found. Any suggestions on how to get text from a customHTML field?



here is the js in case you want to look at it:
 

const customHtmlFieldId = 516;
const checkboxFieldId = 517;
const rowNumberColFieldId = 354;
const tableCommentFieldId = 518;

console.log("Script loaded and running!");

let prevCheckboxValues = LFForm.getFieldValues({ fieldId: checkboxFieldId }) || [];
console.log("Initial checkbox values loaded:", prevCheckboxValues);

LFForm.onFieldChange(function () {
  console.log("onFieldChange triggered!");

  const currentValues = LFForm.getFieldValues({ fieldId: checkboxFieldId }) || [];
  const rowNumbers = LFForm.getFieldValues({ fieldId: rowNumberColFieldId }) || [];

  currentValues.forEach((val, i) => {
    const prevVal = prevCheckboxValues[i] || { value: [] };
    const isNowChecked = Array.isArray(val.value) ? val.value.length > 0 : false;
    const wasChecked = Array.isArray(prevVal.value) ? prevVal.value.length > 0 : false;

    if (isNowChecked && !wasChecked) {
      const rowNum = rowNumbers[i] || "";
      console.log(`Checkbox clicked in row ${i} → RowNumber: ${rowNum}`);

      window.currentRowIndex = i;

      // Build dynamic modal HTML
      const modalHtml = `
        <div style="position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; background: rgba(0,0,0,0.6); z-index: 9999; display: flex; align-items: center; justify-content: center;">
          <div style="background: white; padding: 20px; max-width: 500px; width: 90%; border-radius: 8px;">
            <h3>Row ${rowNum} Comment</h3>
            <textarea id="modalTextarea" rows="4" style="width: 100%; margin-bottom: 10px;"></textarea>
            <button type="button" class="btn btn-primary" onclick="window.saveAndCloseModal()">Save & Close</button>
            <button type="button" class="btn btn-default" onclick="window.closeMyModal()" style="margin-left: 5px;">Close</button>
          </div>
        </div>
      `;

      // Inject modal into Custom HTML field
      LFForm.changeFieldSettings({ fieldId: customHtmlFieldId }, { content: modalHtml })
        .then(() => {
          console.log("Modal HTML injected (dynamic)");
        });
    }
  });

  prevCheckboxValues = currentValues;
}, { fieldId: checkboxFieldId });

// Global handlers
window.closeMyModal = function () {
  LFForm.changeFieldSettings({ fieldId: customHtmlFieldId }, { content: "" });
  console.log("Modal closed without saving");
};

window.saveAndCloseModal = function () {
  const textareaEl = document.getElementById("modalTextarea");
  if (!textareaEl) {
    console.warn("Textarea not found when saving!");
    return;
  }

  const commentText = textareaEl.value || "";
  console.log("💬 Save & Close clicked, comment:", commentText);

  LFForm.setFieldValues({ fieldId: tableCommentFieldId, index: window.currentRowIndex }, commentText)
    .then(() => console.log(`Comment saved to row ${window.currentRowIndex}: ${commentText}`))
    .catch(err => console.warn("Failed to save comment:", err));

  LFForm.setFieldValues({ fieldId: checkboxFieldId, index: window.currentRowIndex }, { value: [] })
    .then(() => console.log(`Checkbox in row ${window.currentRowIndex} unchecked`))
    .catch(err => console.warn("Failed to uncheck checkbox:", err));

  LFForm.changeFieldSettings({ fieldId: customHtmlFieldId }, { content: "" });
  console.log("Modal closed after save");
};

I keep getting closer and closer!

Thanks so much

0 0
replied on July 22

Right now you can't get any custom html values via the LFForm object. I.e., textarea, inputs, checkboxes, etc.

I would recommend using a form field and the section modal approach so you can use the LFForm object to retrieve the field value

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

Sign in to reply to this post.