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

Question

Question

Select multiple checkboxes based upon several single-line lookup fields

asked on January 10 Show version history

I've been through all of the articles and attempted to implement, but none of them were what I am looking work.

 

Since Forms still does not have the ability to assign lookup data to checkboxes, I am having the data placed into single line fields at the bottom.

 

Current process - based on a unique ID (SIC1234) the lookups pull back the materials and where they are stored.  There are several other columns in the databse that are either a '1' for yes or '0'.  These indicate management practices for that particular facility.

 

I'm looking for the JS code that would tick each box associated with the single line field.  

 

Table Class (if needed) is .FuelsMaterialStorageTbl

Checkbox class inside the table is .FuelsMMPCheckbox

Each checkbox option has been shortened to an acroynm for easier use.  Screenshots are below:

 

Form that loads the material and location based on DB lookup (these are seperate tables because I couldn't get "append new rows" to work with multiple material types.

These are the hidden fields that are either 1 or 0 based on DB lookup.  

 

Test DB

 

Checkbox Values:

 

I just need to know the best way to associate that when ISP_Hidden_Fuels_MMP_None is 1, that the "none" checkbox is selected.

ISP_Hidden_Fuelds_MMP_SPP is 1, the Spill Prevention Program checkbox is selected.

And so on.


​​​​​​​Thank you in advance, I truly appreciate the help.

0 0

Answer

SELECTED ANSWER
replied on January 17 Show version history

Hey everyone, I kept at it and finally got a solution to what I needed.  I truly hope those who are searching for this type of solution find this helpful:
 

.FuelsMMPCheckbox is a CSS class for my table

 

I kept the standard field ID's (#q94, #q99, etc)

I have a hidden field for each checkbox option, that fills from a DB lookup.  Either 1 for yes, 0 for no.

 

Respond back if you have any questions.

 

// Function to update checkboxes based on storage plan values
function updateCheckboxes() {
  // Clear all checks and lookup text areas for FuelsMMPCheckbox
  $('.FuelsMMPCheckbox .choice input').prop('checked', false);
  $('#q94 textarea, #q99, #q100, #q101, #q102, #q103, #q104, #q105, #q115 textarea').val('');

  // Define checkbox values and corresponding field IDs
  const checkboxes = {
    "None": "#q94",
    "SPP": "#q99",
    "MAGC": "#q100",
    "MUGC": "#q101",
    "DRSA": "#q102",
    "SCND": "#q103",
    "SCD": "#q104",
    "VC": "#q105",
    "Other": "#q115",
  };

  // Check the values and set checkboxes accordingly
  Object.entries(checkboxes).forEach(([value, field]) => {
    if ($(field + ' :input').val() === "1") {
      $('.FuelsMMPCheckbox .choice input[value="' + value + '"]').prop('checked', true);
    }
  });
}

// Fill Checkboxes Automatically Based On Storage Plan
$(document).ready(function () {
  // Call the function when the form loads
  updateCheckboxes();

  // Bind the updateCheckboxes function to the change event of the specified fields
  $('#q94 :input, #q99, #q100, #q101, #q102, #q103, #q104, #q105, #q115 :input').on('change', function () {
    updateCheckboxes();
  });

  // Insert All JS above this line - everything below is close brackets
});

 

0 0

Replies

replied on January 10

Since you're asking for javascript, I assume you're using the Classic Designer.

This Answers post describes the steps taken to populate checkbox values via lookup in the Classic Designer:

https://answers.laserfiche.com/questions/211300/Populate-Checkbox-options-based-on-Database-Lookup#211314

I hope that helps!

1 0
replied on January 10

I did run across that in my search, but it seemed complicated by placing the lookup values into a multi-value box, and separating them with a | before using an array to process them.  Is there not a more straightforward way?

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

Sign in to reply to this post.