Page 1 of 1
eliminate redundant choices in lookup list
Posted: Tue Dec 04, 2012 2:16 pm
by lightkong
I refer to the popular Invoice with subform allowing multiple invoice line items to be populated by lookup and selecting a product code. Every time a new invoice line item is added, the lookup list will contain all products, including those that were on the saved invoice already. Is there a way to limit the lookup to only those products that are not currently saved in the db as line item of that particular invoice?
Re: eliminate redundant choices in lookup list
Posted: Wed Dec 05, 2012 5:16 am
by admin
lightkong,
There are times you need the same thing twice..
Captureq.PNG
Steven
Re: eliminate redundant choices in lookup list
Posted: Wed Dec 05, 2012 5:24 am
by lightkong
I understand that. But for some cases we need to limit the list to only those items not yet selected.
Is this possible at all? Or perhaps lookup is not the right object for such requirement, or some other way...?
Re: eliminate redundant choices in lookup list
Posted: Wed Dec 05, 2012 6:13 am
by admin
lightkong,
The best answer I can give you is add (something like) this JavaScript to your form..
Code: Select all
function nuBeforeSave(){
if (isDuplicate()){
return false;
}
return true;
}
function isDuplicate(){
var ar = Array();
var used = Array();
ar = nuSubformRowArray('FMinvoice_item');
for(var i = 0 ; i < ar.length ; i++){
var id = '#code' + ar[i] + 'tri_product_id';
if(used.indexOf($(id).val()) == -1){
used[used.length] = $(id).val();
}else{
alert($(id).val() + ' on line ' + (i+1-0) + ' has already been used');
return false;
}
}
return true;
}
Steven