Remove selected values from dynamic list
Moderators: Jon, Steve, Ian, Dave
-
- Ebase User
- Posts: 53
- Joined: Wed Jan 02, 2013 4:23 pm
- Location: Lyndhurst, Hampshire
- Contact:
Remove selected values from dynamic list
I have a dynamic list within a repeater, that allows the user to enter a postcode and select a matching address from the list, as many times as required. Selected addresses are added to an Ebase table. How can I filter the dynamic list to not show addresses that have already been selected? Using Ebase 4.5.4
0 x
-
- Moderator
- Posts: 1342
- Joined: Wed Sep 12, 2007 12:49 pm
Re: Remove selected values from dynamic list
One way would be to build the list using script code instead of using a Dynamic List. Then you could check whether the address should be omitted or not.
For example you could build a list from a database table something like this:
For example you could build a list from a database table something like this:
Code: Select all
var addresses= [];
var sql = "select address from addresses where post-code = 'xxxxxx'";
services.database.executeSelectStatement(MY_DATABASE_CONNECTION, sql,
function (row)
{
var addr = row.address;
// exclude addresses used previously
var n = tables.previous_addresses.findRow(tables.previous_addresses.address, addr);
if (n == -1) {
addresses.push(row.address);
}
});
fields.addressesField.createCustomList(addresses);
0 x
-
- Ebase User
- Posts: 53
- Joined: Wed Jan 02, 2013 4:23 pm
- Location: Lyndhurst, Hampshire
- Contact:
Re: Remove selected values from dynamic list
Thanks Jon but I don't have access to the DatabaseServices class, looks like this was added in 5.2
Any way of doing something similar in 4.5.4?
Regards,
Edd
Any way of doing something similar in 4.5.4?
Regards,
Edd
0 x
-
- Moderator
- Posts: 1342
- Joined: Wed Sep 12, 2007 12:49 pm
Re: Remove selected values from dynamic list
Sorry about that. You could do the same thing using a Database Resource to load a table, or alternatively something like this (this is a more long-winded alternative to services.database that should work with V4.5):
Code: Select all
var con = system.getDatabaseConnection("MY_DATABASE_CONNECTION");
var stmt;
var rs;
var addresses= [];
try
{
stmt = con.prepareStatement("select address from addresses where post-code = 'xxxxxx'");
rs = stmt.executeQuery();
while (rs.next())
{
var addr = rs.getString("address");
// exclude addresses used previously
var n = tables.previous_addresses.findRow(tables.previous_addresses.address, addr);
if (n == -1) {
addresses.push(row.address);
}
}
}
finally
{
// it is very important to close any open result sets, statements and connection in this manner
// otherwise there will be a resource leak.
if (rs) rs.close();
if (stmt) stmt.close();
if (con) con.close();
}
fields.addressesField.createCustomList(addresses);
0 x
-
- Ebase User
- Posts: 53
- Joined: Wed Jan 02, 2013 4:23 pm
- Location: Lyndhurst, Hampshire
- Contact:
Who is online
Users browsing this forum: No registered users and 5 guests