select2 selection

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
konfuzion
User
Posts: 378

select2 selection

Post by konfuzion »

<select id="x_myfield" ...>
<option value="1">one</option>
<option value="2">two</option>

$('#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 work

What did I miss?


arbei
User
Posts: 9281

Post by arbei »

You may search "updatedone" in this forum or in the docs.


mobhar
User
Posts: 11660

Post by mobhar »

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";

konfuzion
User
Posts: 378

Post by konfuzion »

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'
	});
	}

mobhar
User
Posts: 11660

Post by mobhar »

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.


konfuzion
User
Posts: 378

Post by konfuzion »

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 fields

4 groups
1 group = 1 button + 5 unique fields

In 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 selected

So 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)


konfuzion
User
Posts: 378

Post by konfuzion »

I see, I think Row_Rendered server event for default selecting may be useable in my case also, will give it a try.


Post Reply