Update select box dynamically.

Use this board to ask questions or have discussions with other Rich Displays users.
Post Reply
Estibarna
New User
Posts: 10
Joined: Wed Sep 16, 2015 2:57 am
First Name: Sergio
Last Name: Martinez Roig
Company Name: Estibarna, CPE
State / Province: Outside Canada/USA
Country: Spain
Contact:

Update select box dynamically.

Post by Estibarna »

Hello,

We are trying to update select box records dynamically using javascript.

As you can see in DESMER definition field:
DESMER definition.png
DESMER definition.png (112.81 KiB) Viewed 855 times
we have one query with 4 parameters, the second parameter is which we want to change.

One button with this javascript code in onClick event do this:

Code: Select all

function botonMercanciasFavoritos() {
	var classes = getObj("merFav").classList;
	classes.toggle("pui-solid-button-no");
	classes.toggle("pui-solid-button-yes");

	if (get('codFav') == 'S') {
		pui.set("codFav", "N")
	} else {
		pui.set("codFav", "S")
	}
	applyProperty("DESMER", "choices parameter value 2", get('codFav'));
	applyProperty("DESMER", "field type", "select box");
}
When record format loads we can see in Developer tools a call to PUI0009103.PGM with this parameters:
P2=N.png
P2=N.png (41.91 KiB) Viewed 855 times


When button is pushed another call to the same program with P2 updated
P2=S.png
P2=S.png (48.49 KiB) Viewed 855 times
we can see 'Loading ...' in select box, but the records received are the same

Using SQL Query first one retrieve 288 records and second one 45:
Scott Klement
Experienced User
Posts: 2711
Joined: Wed Aug 01, 2012 8:58 am
First Name: Scott
Last Name: Klement
Company Name: Profound Logic
City: Milwaukee
State / Province: Wisconsin

Re: Update select box dynamically.

Post by Scott Klement »

It is because you have the "choices parameter 2" property bound to the 'cFavorito' variable on the server.

When the SQL query is re-run, it will get the value of that parameter from the server-side program rather than from the JavaScript code in the display file.

To fix the problem:

1) Add a hidden output field to the display. Bind it's value to 'cFavorito'
2) Set the id property of the new output field to 'cFavorito'
3) In the Elements tab, make sure the new hidden output field comes before the select box. If necessary, highlight the field in the Elements tab, and click the 'up' arrow to move it before the select box.
4) Change 'choices parameter value 2' to not be bound, but instead set to the following: js: pui.get('cFavorito')

When the display loads, it will run JavaScript code to get the value of the hidden field you added and will insert it into the 'choices parameter value 2'. Since the server-side code no longer sees this value as bound, it will get it from the value you set in JavaScript. When you later do the applyProperty() to set the new value, it will use that new value since it's drawing the value from JavaScript rather than a bound field.

You can learn more about how database-driven widgets get their SQL parameters here:
https://docs.profoundlogic.com/x/oYDQ
Estibarna
New User
Posts: 10
Joined: Wed Sep 16, 2015 2:57 am
First Name: Sergio
Last Name: Martinez Roig
Company Name: Estibarna, CPE
State / Province: Outside Canada/USA
Country: Spain
Contact:

Re: Update select box dynamically.

Post by Estibarna »

Once again,

Thank you very much Scott,
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests