You are viewing limited content. For full access, please sign in.

Question

Question

Default value for dropdown in a collection that is populated by a database lookup

asked on December 2, 2020 Show version history

I saw couple of posts on this topic using Javascript but did not find the solution I am looking for.

Dropdown is in a collection, dropdown will be populated from database.  How do we default to the first value returned? 

0 0

Answer

SELECTED ANSWER
replied on December 3, 2020

okay im assuming that you set your look up rule to fill always and you dont put anything in default.. i would use the onlookupcompleted function to then set the default value of your dropdown. 

 

keep in mind that you will probably have to use for each ("Your Collection") and $(this).find("your dropdown name").select 

 

the selct function will let you set the defualt .. here is example link 

https://answers.laserfiche.com/questions/156804/Set-value-in-drop-down-list-with-Javascript

 

ORRRRRR 

 

use the foobar default logic built into forms: 

 

https://answers.laserfiche.com/questions/68625/Set-dropdown-field-default-when-populating-with-database-query?sort=newest

 

i havent confirmed this myself but seems reasonable for it to still work. 

0 0
replied on December 3, 2020

Thank you!

1 0

Replies

replied on December 1, 2021

  $(document).on("lookupcomplete", function(){
    
    console.log("look up complete.. start the parent item for dropdown");
     var item = $('select[id=Field40] option:nth-child(2)').text()
    $('[id=Field40]').val(item).change();
  });
  

this is better and a full code of it. just change the field to your drop down. maybe put a filter for which look up finished so you dont interrupt things as you continue to build. 

 

note to self. 

1 0
You are not allowed to follow up in this post.

Sign in to reply to this post.