NetTalk Central

Author Topic: Multi-select on drop list or lookup  (Read 4578 times)

kingja

  • Sr. Member
  • ****
  • Posts: 261
    • View Profile
    • Email
Multi-select on drop list or lookup
« on: November 21, 2012, 07:56:58 PM »
     I'm struggling with multi-select issues.  I have placed a text field on a form.  I also placed a copy of the same field (using a different equate) next to the original field.  The copy is set as a drop down with multi-select set.  If I select multiple items, they are displayed in the original text field.  Please see attached image.
     If I save the form then click change to see the results, the text field now contains the following:

         ;|;multiple;|;

     I have seen other postings here about this issue but none have explicitly explained how to get the multiple items from the drop list into another control.  Can anyone tell me which embed should be used, and where the multiple items selected are stored?

     Ideally I would like to use the lookup capabiity.  I have this in use in many other areas but it only allows a single selection to be returned.  Does anyone know of a way to do multiple selections from a lookup list?

Thanks,

Jeff King


[attachment deleted by admin]

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11244
    • View Profile
Re: Multi-select on drop list or lookup
« Reply #1 on: November 21, 2012, 09:16:59 PM »
Hi Jeff,

Perhaps take one of the shipping examples, and tweak it to show the sort of situation you have in mind.
Then post that here, and I can take a look at when code should go where.

cheers
Bruce

kingja

  • Sr. Member
  • ****
  • Posts: 261
    • View Profile
    • Email
Re: Multi-select on drop list or lookup
« Reply #2 on: November 21, 2012, 09:49:23 PM »
Bruce,

     Thanks...I'll be away for the Thanksgiving holiday until Friday.  I'll post an example then.

Jeff

kingja

  • Sr. Member
  • ****
  • Posts: 261
    • View Profile
    • Email
Re: Multi-select on drop list or lookup
« Reply #3 on: November 23, 2012, 12:29:11 PM »
Bruce,

     I have attached a modified version of example web33.  I placed a copy of the messages text control to the right of the original.  I changed it to a drop list with three items.  Selecting multiple items does cause these items to appear in the original messages text control, seperated by the ;|; delimiter.  However, saving the form and then viewing again shows that ;|;multiple;|; is actually saved in the messages field.
     So this brings up some questions:
1.  what happened to the data, why was it converted to ;|;multiple;|;?
2.  is there a specific variable that I can access that stores the selected items chosen from the drop list?
3.  which embeds should I use to manage all this?

     As I mentioned earlier, it would be better to use a look up button next to the messages text control.  I do this in other areas of the app and it is a more consistent and elegant solution.  However, the look up method only allows one item to be selected.  Is there a way to allow multiple selections from a lookup?

     By the way, I renamed the app file to web33.clw as this forum would not allow files with an app extension.

[attachment deleted by admin]

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11244
    • View Profile
Re: Multi-select on drop list or lookup
« Reply #4 on: November 23, 2012, 10:10:18 PM »
Hi Jeff,

Because of the way dict conversions work in C8, and because we ship examples in pre-C8 format, you _must_ include the dict when posting examples.

Zip them together and attach as a zip.

cheers
Bruce

kingja

  • Sr. Member
  • ****
  • Posts: 261
    • View Profile
    • Email
Re: Multi-select on drop list or lookup
« Reply #5 on: November 24, 2012, 06:18:21 AM »
Bruce,

     Sorry about that...attached is a zip containing the app and dct files.

Thanks,

Jeff

[attachment deleted by admin]

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11244
    • View Profile
Re: Multi-select on drop list or lookup
« Reply #6 on: November 25, 2012, 10:13:47 PM »
Hi Jeff,

Thanks for the example. It took me a bit of time and investigation to remember how the multi-select works.

The first thing to bear in mind is that there's not direct Clarion equivalent for a multi-select, the way there is for a string or number. So _what_ you want to do with the multi-select is kind of up to you. Some people store them in a string, as a comma separated list or something - others write them in an array, and others write them to a child file.

So, the idea is you will need to decide how you are going to store them, and then write some appropriate embed code to do that.

The embed code goes into the ValidateValue::fieldEquate routine for the field, right at the top before the generated code.

In this case ValidateValue::MAI:AutoResponseText. (Be careful to get the right one - your naming of equates in the example is backwards, so could lead to confusion.)

- the call p_web.GetPicture('MAI:AutoResponseText') returns the number of items in the result. (For example if you selected 3 items, this would be set to 3.)
- the individual items are stored as the field name, plus the index number. For example, MAI:AutoResponseText1 and MAI:AutoResponseText2.

So the code could look something like this;

  if MAI:AutoResponseText = ';|;multiple;|;'
    n = p_web.GetPicture('MAI:AutoResponseText')
    MAI:AutoResponseText = ''
    loop x = 1 to n
      MAI:AutoResponseText = clip(MAI:AutoResponseText) & ',' & p_web.GetValue('MAI:AutoResponseText' & x)
    end
  end 


I probably don't recommend you putting a Text box, and a multi-line select on the same form with the same name. They'll both "submitting" their value into the same variable, so there's likely to be some unexpected behavior at some point. but I assume you're just doing this for debugging purposes.

Cheers
Bruce


kingja

  • Sr. Member
  • ****
  • Posts: 261
    • View Profile
    • Email
Re: Multi-select on drop list or lookup
« Reply #7 on: November 26, 2012, 04:29:47 AM »
Bruce,

Thanks for the detailed response.  I'll work with this and report back with my progress.

Jeff