4 Replies Latest reply on Dec 5, 2014 12:31 PM by ByteTheBullet

    Slide Controls & Records w/ Variable Image Counts

    ByteTheBullet

      I have a database where each record in a given table could have a variable number of images associated with it (0 to 4), and I'm trying to plan out the schema and how to build one of the layouts. My first instinct is to keep the container field in a separate table related to the first. That's all well and good from a data normalization perspective, but where I'm unable to come up with an elegant solution is how to show the variable numbers of images on a layout.

       

      One thought was to have a repeating container field and use a slide control, with one repetition per pane in the slide control. This seems somewhat tedious, since I don't see a way to use a calculation to denote which repetition should appear on which "panel" of the slide control. I'm also just not a huge fan of repeating fields. This also leaves me with the problem of having "empty" panels in the slide control for records that do not have the maximum number of images. One thought was to have a number of stacked slide controls and set the visibility on each one to be visible only if the number of images equals the number of panels in that slide control. Basically, if a record had two images, only the slide control with 2 panels would be visible. The slide controls with 3 or 4 images (and the container that would need to be included for cases of only a single image) would be invisible. If I use a repeating container field to store the images, this would depend on the images being stored in consecutive repetitions with no "gaps". I can live with that if I have to, but it just seems the wrong way to do things.

       

      If I use a related table with a non-repeating container field, I'm not sure how I can make the slide control work since I'd have to show the container from a related record, with the first related record in the first panel, the second in the second panel, etc. I know how to get the *count* of related records, just not how to display the 1st in the 1st panel, 2nd in the 2nd panel, etc.

       

      I'm still fleshing this particular database out, but I'm likely to have a similar need for text as I do for images (multiple text fields related to a given parent record).

       

      So, is there a better way to handle this that I'm not thinking of?

        • 1. Re: Slide Controls & Records w/ Variable Image Counts
          erolst

          If you only need to display a single image at a time, simply use a single container field on a single panel, and a counter to keep track of your position within the available images.

           

          Then swap the images, either by using the position counter to grab an ID from the list of related IDs and set a field that drives another relationship into Images, or by directly inserting the image into a global container field, using a script along the lines of

           

          Set Field [ MyTable::gMyContainer ; GetNthRecord ( Images::image ; $$myImageCounter ) ]

           

          The first approach seems a bit convoluted and requires an additional TO, but has the benefit that you're just setting an ID, instead of copying a potentially massive amounts of image data.

           

          ByteTheBullet wrote:

          I'm also just not a huge fan of repeating fields.

           

          Yes, you shouldn't exactly store your business data in them (and they're a huge trap for beginners), but I've found they have a lot of cool uses for UI purposes.

          1 of 1 people found this helpful
          • 2. Re: Slide Controls & Records w/ Variable Image Counts
            DrewTenenholz

            Byte --

             

            I think you should be able to use the portal configuration option "starting on row x, show n rows" with one or more slide controls to achieve what you describe, and maintain good data structure.  Effectively, you can get different one-row portals showing successive related records.

             

            For example, if you created a 4-item slide control, put a portal on each one to the related images with the option to start on rows 1,2,3,4 respectively and show only 1 row, then place the container field inside each portal.  That will make the 'second' image only appear on the 'second' slide control.

             

            You can then duplicate the entire slider three more times, set up the conditional object hiding, remove one or more sliders from each, and stack them up.

             

            -- Drew Tenenholz

            • 3. Re: Slide Controls & Records w/ Variable Image Counts
              mark_scott

              Hello Byte,

               

              Agree with the replies, as well as your gut instinct to use a related table rather than a repeating field. 

               

              One potential anwer to your problem

              ByteTheBullet wrote:

               

              …This also leaves me with the problem of having "empty" panels in the slide control for records that do not have the maximum number of images. …

               

              might lie in the very clever Perpetual Slide Panel technique demonstrated over at Anvil Dataworks.

               

              hth,

               

              Mark

              1 of 1 people found this helpful
              • 4. Re: Slide Controls & Records w/ Variable Image Counts
                ByteTheBullet

                Thanks for the reposnses, everyone!

                I think DrewTenenholz's suggestion is going to best suit my needs, at least for now. I hadn't thought about using a single row portal on each slide panel. I understand that it essentially hard codes my options, but I'll take a look at the example Mark Scott linked to and the suggestion from erolst for a longer-term solution. If I understand correctly, erolst's suggestion wouldn't even need a slide control- just a global container, some basic scripts, and some variables to swap the displayed image as the end user navigates between them.

                 

                What I'd *really* like is a nice simple way to add additional images and have the slide panel automatically increases panels as needed, but I just don't see a way to do that.

                 

                Anyway, thanks again!