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

Question

Question

How to use a database lookup to only select a default choice in a drop down list

asked on October 14, 2016

When we use a lookup to populate a drop down it fills but replaces the list of choices in the drop down with only the matched lookup item. No longer can the user select the default list of drop down choices. We want to use the lookup to put a default choice in but allow the user to override the lookup and select from the original list. Alternatively, we considered using a radio button instead but don't seem to be able to fill that from a lookup. How can we accomplish this?

0 0

Answer

SELECTED ANSWER
replied on October 14, 2016 Show version history

Hi Jeremy,

To add default values to a lookup, I've place the default values into the database view. If you're using an older version of Forms, you could wait a couple of seconds then add your defaults to the drop down. In Forms 10, there is a call back when a lookup has completed... It's a bit messy (to clarify, I'm more comfortable with SQL than with JavaScript) so I prefer to just add the defaults to the database view/lookup with the "union all" command in SQL view's definition.

as in...

create view formsLookup as
  select forename, surname, staffID
  from staflist
  union all
  select 'defaut name1', 'default surname 1', 'default id1'
  union all
  select 'defaut name2', 'default surname 2', 'default id2'

 

As for populating the radio button, I've had similar issues. Eventually my solution was to have the lookup populate a hidden text field and use javascript to set the radio button based on the value of the hidden text field.

0 0
replied on October 14, 2016

Hey thanks Ben! I appreciate your super speedy answer. Could you give me a sample of the javascript to fill a radio button that way? I'm pretty sure we can figure it out once we have the basic idea.

0 0
replied on October 15, 2016

This javascript will run after a database lookup populates a text field. The value in the text field is then used to set a radio button. Finally, the radio button is triggered to activate a field rule.

 

    $('.myText input').change( function() {
      $('.myRadio input').val([$('.myText input').val()]);
      $('.myRadio input').change();
    });

 

1 0
replied on October 16, 2016

I'm just getting started with Javascript and Forms.  When you use .myRadio in the above, is that because you have set the CSS Class for the field to myRadio? Could you be using the #q7 type reference format instead?

0 0
replied on October 16, 2016

Hi Clarence.  yes and yes smiley

 

 

 

 

 

0 0

Replies

replied on October 16, 2016
1 0
replied on October 17, 2016

Fantastic! Thank you.

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

Sign in to reply to this post.