Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

eliminate redundant choices in lookup list

Post Reply
lightkong
Posts: 2
Joined: Mon Nov 26, 2012 1:46 am

eliminate redundant choices in lookup list

Unread post 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?
admin
Site Admin
Posts: 2814
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 25 times

Re: eliminate redundant choices in lookup list

Unread post by admin »

lightkong,

There are times you need the same thing twice..
Captureq.PNG
Steven
You do not have the required permissions to view the files attached to this post.
lightkong
Posts: 2
Joined: Mon Nov 26, 2012 1:46 am

Re: eliminate redundant choices in lookup list

Unread post 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...?
admin
Site Admin
Posts: 2814
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 25 times

Re: eliminate redundant choices in lookup list

Unread post 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
Post Reply