Listbox - click value changes record

Questions and answers for designing and implementing forms in Servoy

Listbox - click value changes record

Postby DANNYHICKS0102051348647391 » Wed Sep 26, 2012 11:10 am

Hi, basically I have a list box with a value list of customers based on a customer table.

When clicking the the customer, I want it to change to that record so I can get the customer name and customer ID which I can then store and use on a different form to create a new record in another table using the cust id and name .


Anyone know the best way to do this?
DANNYHICKS0102051348647391
 

Re: Listbox - click value changes record

Postby ROCLASI » Wed Sep 26, 2012 11:28 am

Hi Danny,

First of your listbox should already give you the ID (real value vs display value).
And a field has an onDataChange event (see properties view) that you can use to act on the selection. Just use the newValue parameter of this event to get the real value of your combobox and use this to create the new record.

Hope this helps.
Robert Ivens
SAN Developer / Servoy Valued Professional / Servoy Certified Developer

ROCLASI Software Solutions / JBS Group, Partner
Mastodon: @roclasi
--
ServoyForge - Building Open Source Software.
PostgreSQL - The world's most advanced open source database.
User avatar
ROCLASI
Servoy Expert
 
Posts: 5438
Joined: Thu Oct 02, 2003 9:49 am
Location: Netherlands/Belgium

Re: Listbox - click value changes record

Postby DANNYHICKS0102051348647391 » Wed Sep 26, 2012 11:35 am

Thanks for your reply. How do I use the new value event in terms of writing the code for it. I need it so on data change, it gets the value and stores it in variables.

Thanks for your help
DANNYHICKS0102051348647391
 

Re: Listbox - click value changes record

Postby matthewbrice » Fri Sep 28, 2012 3:03 am

If you have the listbox dataprovider property set to a form or global variable, there is no need to have a onDataChange event to store the new value; the listbox control is "bound" to the variable. You just want to be sure that the return value of the valuelist that is associated with the listbox is the pk of the customer that is selected. The pk is all you would need to reference any field in that particular customer record. If you want some event to happen when you select a different customer, you can, as suggested already, use the onDataChange method that is attached to the listbox. The autogenerated servoy code will look like this:

Code: Select all
/**
* Handle changed data.
*
* @param {String} oldValue old value
* @param {String} newValue new value
* @param {JSEvent} event the event that triggered the action
*
* @returns {Boolean}
*
* @properties={typeid:24,uuid:"FE8D2254-97BA-4010-B21A-E85EBCA7A437"}
*/
function onDataChange(oldValue, newValue, event) {
   // TODO Auto-generated method stub
   return true
}


Servoy already will provide you with the paramaters shown above oldValue, newValue, event. You just need to figure what you want to do next.
Matt Brice
matthewbrice
 
Posts: 36
Joined: Wed Jun 13, 2012 6:42 pm


Return to Forms

Who is online

Users browsing this forum: No registered users and 2 guests