$('#x_myfield').val('1'); // Select the option with a value of '1'
$('#x_myfield').trigger('change'); // Notify any JS components that the value changed
I added this code to make custom selection from select2 on initial load but nothing is being selected.in jsfiddle it works but through phpmaker it doesn’t workWhat did I miss?
Alternatively, if you don’t want to use jQuery/Javascript, then you may simply use Row_Rendered server event to display the selected value in Select2 control when the page has been just loaded.Let’s say you want to make customer Around the Horn (AROUT) as the default selected value in CustomerID field in Add Page of orders table, then simply put this following code in Row_Rendered server event that belongs to the orders table:
if (CurrentPageID() == "add")
$this->CustomerID->CurrentValue = "AROUT";
I’m trying to get it working in the Modal Multi-Update Window but there’s something wrong with this code. I want to trigger the auto select after the Modal window is shown.
$(window).on('shown.bs.modal', function (e) {
// do something...
$(document).on('updatedone', function(e, args) {
$('#x_myfield').val('2'); // Select the option with a value of '2'
});
}
I suggest you to simply use Row_Rendered server event instead of Startup Script, since the server event will also handle the page that displayed via Modal dialog window.
For Multi-Update and using the example above, you may only change that code to:
if (CurrentPageID() == "update")
$this->CustomerID->CurrentValue = "AROUT";
and make sure you have already enabled Multi-Update and Modal dialog option under Table setup → Multi-Update Page of current table.
Tks for the suggestion but actually, I want to make the Modal Multi-Update more flexible and dynamic.For example, I have 4 different buttons. and 20 unique fields4 groups
1 group = 1 button + 5 unique fieldsIn List page are 4 buttons, clicking on the button results in different Multi-Update Modal Windows.Group 1 = If click button#1 then Modal pops up with 5a fields displayed with the correct option selected
Group 2 = If click button#2 then Modal pops up with 5b fields displayed with the correct option selected
Group 3 = If click button#3 then Modal pops up with 5c fields displayed with the correct option selected
Group 4 = If click button#4 then Modal pops up with 5d fields displayed with the correct option selectedSo it’s best if I can do everything in Jquery so it’s fully dynamic.Currently, hiding the 15 other fields and checking the checkboxes works for each group, only the auto-select of select options is not working (yet)