When only a single entry in drop-down, make it the default - InfoPath Dev
in

InfoPath Dev

When only a single entry in drop-down, make it the default

Last post 08-04-2014 11:03 AM by PaulaKern. 5 replies.
Page 1 of 1 (6 items)
Sort Posts: Previous Next
  • 11-30-2011 05:56 AM

    When only a single entry in drop-down, make it the default

    Hello,

    If I've got a drop-down list that pulls its entries from an external connection.

    When it discovers only a SINGLE ENTRY for that list which is different every time and can't be hard-coded into a rule, I'd like it to auto-populate the field with that entry. This can't be too difficult, can it? :)

    Similarly, if there is more than one item in the drop-down, is there a way to get it to push the top option as the default?

    Thanks!

    Chris ... er, Arthur Fonzarelli!
  • 11-30-2011 08:07 AM In reply to

    Re: When only a single entry in drop-down, make it the default

    It actually sounds to me as if you want the same scenario to occur in all instances - if there is just one option, default to that, and if there are many options, default to the first - since the first case (only one option) is equivalent to the second case, this is really straightforward. Just set the default value of your main data source field to the field desired in the secondary data source. By default, if that field repeats, InfoPath should always choose the first instance.
    Hilary Stoupa

  • 12-01-2011 05:42 AM In reply to

    Re: When only a single entry in drop-down, make it the default

    Hilary,

    First off - thanks for taking the time to answer! Always appreciated! :)

    The issue with what you've suggested - I never know what that exact value will be.  Suppose I have a drop-down list set to go off and get a list of the US Cities today where the temperature was over 80 degrees - States[Temperature > 80].  Every day that might be different. But what I want is for it to choose by default the 'top' city on the list.  So if there is only 1 (Las Vegas let's say), I don't want to have to click in that cell to actually choose Las Vegas - it will be chosen by default.  And if there are more than 1 (Reno and Dallas let's say), I want it to automatically choose the one that's on top of the list (Dallas if I've got it sorted correctly) and if I don't bother clicking, it will choose Dallas by default.

    But maybe I'm misinterpreting what you're saying which is normally my issue ... 

    Thanks!

    Chris ... er, Arthur Fonzarelli!
  • 12-01-2011 09:01 AM In reply to

    Re: When only a single entry in drop-down, make it the default

    InfoPath doesn't care if the secondary data source has one or a hundred rows - the XPath to the field is going to return the first node, unless you've specified with a filter which row you want.

    So, let's say I have a secondary data source called "Cities". It has a field called City.

    The XPath looks like:

    Cities/Row/City

    Row is repeating.

    My main data source field is called SelectedCity. It is bound to a dropdown control.

    The dropdown uses my Cities data source to provide the values to the dropdown.

    If I set the default value for SelectedCity (my main data source field) to my secondary data source field:

    Cities/Row/City

    SelectedCity will always default to the first entry in that data source.

    Does this make sense? If not, I can put together a quick sample form.

    Hilary Stoupa

  • 12-01-2011 12:17 PM In reply to

    Re: When only a single entry in drop-down, make it the default

    Hilary,

    Excellent!  Thanks a million!

    My issue was I have a different Value vs Display Name ... going through the logic you described got me to readjust my focus and then I got 'er working! ;)

    Chris.

     

     

    Chris ... er, Arthur Fonzarelli!
  • 08-04-2014 11:03 AM In reply to

    Re: When only a single entry in drop-down, make it the default

     What could I do if these choices are filtered for a particular user?  I can get the default but it gives me all and not just the ones for the particular filter?  Thanks for any direction you can give.

Page 1 of 1 (6 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.