Hi,
I am using a modal dialog lookup with select.
The lookup fields are:
Display field #1: ks_stelle
Display field #2: ks_la
Display field #3: Jahr
Display field #4: ks_gueltigThe database values of ks_gueltig are 0 or 1.
The shown values are No for 0 and Yes for 1…I am trying to disable the options with ks_gueltig == 0.
I should show all options but the options with ks_gueltig == 0 should NOT be selectable.
I used the following code in “startup script” but have no success.
Any idea where to start?
Startup Script
$(document).on("shown.bs.modal", function(event) {
var modal = $(event.target); // Get the modal that was just shown
// Check if it's the modal lookup (based on modal title or other unique properties)
if (modal.find(".modal-title:contains('Lookup')").length) {
// Target the select dropdown inside the modal (adjust #your_field_id to your field's actual ID)
var select = modal.find("select#x_Kostenstelle");
// Loop through each option in the select dropdown
select.find("option").each(function() {
var option = $(this);
var ks_gueltig_value = option.data("ks_gueltig"); // Assuming ks_gueltig value is passed as data attribute
// Disable option if ks_gueltig is 0
//if (ks_gueltig_value == 'No') {
option.prop("disabled", true); // Disable the option
option.css("color", "#999"); // Change color to indicate it's disabled
//}
});
}
});
The “shown.bs.modal” is for the modal dialog, the options of the lookup field are not updated yet. You may search “updatedone” in this forum. Also see Client Script → Example 3.
$(document).on("updatedone", function(e, args) {
var $target = $(args.target);
// Check if the lookup field is the one you're interested in (replace "MyLookupField" with your actual field name)
if ($target.data("field") == "x_MyLookupField") { // Replace with your field name
// Loop through each row in the lookup table
$target.closest("table").find("tbody tr").each(function() {
var $row = $(this);
// Get the value of ks_gueltig from the row (replace 'ks_gueltig' with the actual data-name)
var ks_gueltig_value = $row.find('td[data-name="ks_gueltig"]').text().trim();
// If ks_gueltig == 0, disable the select or mark as non-selectable
if (ks_gueltig_value === "0") {
$row.css("color", "#999"); // Change color to indicate it's disabled
// Disable select element or prevent interaction
$row.find("select").attr("disabled", true); // Disable the select dropdown element in this row
}
});
}
});
Hi,
I just checked again with the following code.
It still show me all the options.
The aim is that it shows all the options but the options (select rows) with ks_gueltig ==0 should not be selectable.
The source table called laboratory_equitment.
The lookup field of source table is: Kostenstelle
Edit Tag:
Select
Use lookup table: checked
Use modal dialog for lookup: checkedLookup Table
Table name: kostenstelle
Link field: ksid
Display field #1: ks_stelle
Display field #2: ks_leitzahl
Display field #3: Jahr
Display field #4: ks_gueltig
$(document).on("updatedone", function(e, args) {
var $target = $(args.target);
// Check if the lookup field is the one you're interested in (replace "MyLookupField" with your actual field name)
if ($target.data("field") == "x_Kostenstelle") { // Replace with your field name
// Loop through each row in the lookup table
$target.closest("kostenstelle").find("tbody tr").each(function() {
var $row = $(this);
// Get the value of ks_gueltig from the row (replace 'ks_gueltig' with the actual data-name)
var ks_gueltig_value = $row.find('td[data-name="ks_gueltig"]').text().trim();
// If ks_gueltig == 0, disable the select or mark as non-selectable
if (ks_gueltig_value === "0") {
$row.css("color", "#999"); // Change color to indicate it's disabled
// Disable select element or prevent interaction
$row.find("select").attr("disabled", true); // Disable the select dropdown element in this row
}
});
}
});
You better debug your code by, e.g. console.log($target.closest(“kostenstelle”)) and see if you can find or what you found is really want to want to find.