1 2 Previous Next 19 Replies Latest reply on Mar 30, 2017 7:32 AM by MichaelManousos

    On/off radio button

    peter.martin@sinclairdesign.com.au

      i understand how to create an On AND an Off radio button, but I can't work out how to make a one-button on/off switch. I'm missing something very simple, I'm sure.

       

      Peter

        • 1. Re: On/off radio button
          erolst

          e.g. use a number field with a checkbox control and a value list of 1; this will switch between 1 and 0, which can be programmatically read as True/False, on/off etc.

          • 2. Re: On/off radio button
            peter.martin@sinclairdesign.com.au

            Sorry, but I'm still missing something! I created a list - On Off List - containing one value, "1".

             

            In the table I created the on/off field as numeric.

             

            I created a checkbox associated with my required on/off field and linked that checkbox to my On Off List.

             

            Firstly, a "1" appeared adjacent to the checkbox and I could not delete it.

             

            Secondly, clicking over the checkbox caused it to turn on and off, but when I converted this field back to an edit box to see the underlying values, I did not see 0 or 1 as I was anticipating. I used Find and sorted on 0 and 1, and in both instances all records were presented!

            • 3. Re: On/off radio button
              erolst

              peter.martin@sinclairdesign.com.au wrote:

              Firstly, a "1" appeared adjacent to the checkbox and I could not delete it.

               

              That is the checkbox label. Simply make the control small enough so you only see the checkbox.

               

              peter.martin@sinclairdesign.com.au wrote:

              Secondly, clicking over the checkbox caused it to turn on and off, but when I converted this field back to an edit box to see the underlying values, I did not see 0 or 1 as I was anticipating. I used Find and sorted on 0 and 1, and in both instances all records were presented!

               

              OK, my earlier description may have been a bit misleading …

               

              For your existing records, the field will be empty; when you check/uncheck the box, it will toggle between empty and 1 (where in a logical sense, empty is also treated as false).

               

              Only if you apply something like

               

              Set Field [ MyTable::myToggleField ; not MyTable::myToggleField ]

               

              will 1 become 0, and 0 one.

               

              As it stands, simply search for field is empty ("=") or not empty ("*").

              • 4. Re: On/off radio button

                It could just be the labels that are confusing you.

                 

                Instead of "1", try "ON" as in the check box example on the right. Everything else is the same that erolst suggested.

                 

                Or, use a radio button as shown on the left.

                FileMaker stores the checkbox (apparently) when you look at the data in FM. That has always confused me coming from enterprise database environments. Yet, if you do anything with the actual data, you'd see that it really is zeros and ones for checkboxes:

                 

                 

                SELECT * (all rows, no WHERE clause) gives you this:

                 

                1,0,1,Jobs

                0,,0,Rodger

                1,,0,Alice

                1,,1,Mike

                1,,1,Beverley

                ,,1,Steve

                1,,0,Fred

                 

                So, FileMaker is actually storing the correct value. The display thing where it shows the actual checkbox control in grid mode is just a helper thing. I don't actually like that checkbox display; I'd rather just see the zero or one.

                 

                -----

                 

                HOPE THIS HELPS.

                 

                - m

                • 5. Re: On/off radio button
                  beverly

                  if you really want to make the single radio button "toggle" on/off, then make it a button (or put a transparent button over it) with the script step calculation:

                  Set Field ( myField ; NOT myField )

                  this changes any 1 to 0 and any 0 to 1, as long as the field is a number field.

                   

                  note: you are not entering the field directly and it should be out of tab order.

                   

                  beverly

                  1 of 1 people found this helpful
                  • 6. Re: On/off radio button
                    karimhanafi

                    Hi Peter and Beverly,

                     

                    If I may add just a little tip to make a skeuomorphic switch. If you are on FM14, while using Beverly's solution, you can use a button bar object with 2 buttons, first button has the off switch and the second has the on switch. Then for each button set the right condition to hide.

                     

                    Off switch Button will be : myField (Off switch hidden if myField is true)

                     

                    On switch button will be: not myField

                     

                    If you are on 12 or 13, you will need 2 buttons as the Button Bar object is new to 14.

                     

                    Take care.

                     

                    Karim

                    • 7. Re: On/off radio button
                      beverly

                      the button bar and hide is a great solution, Karim. I was trying to make the topic "on/off radio button" work.

                       

                      I actually prefer the checkbox with "1". If checked = 1 and thus "sum-able". If not checked = empty or "0" and also can be summarized with 'Not 1'. This type of field can be sorted, searched easily enough and the field sized down to hide the label.

                       

                      a single radio button, OTOH, requires a trick of some sort to turn "off" again.

                      beverly

                      • 8. Re: On/off radio button
                        Jade

                        While we're drifting a little off topic,  you may use the attached on/off sliding button emulating the "iOS" style.  Feel free to copy, modify, distribute and add to it as you like.

                         

                        Button.tiff

                        • 9. Re: On/off radio button
                          peter.martin@sinclairdesign.com.au

                          Thank you all. Using bits from each, I have come up with a solution that perfectly meets my requirements. Peter

                          • 10. Re: On/off radio button
                            erolst

                            Here a sample file that demonstrates a few simple methods.

                             

                            The generic script is … well, deployable generically, but you may not like the slight delay between field entry and exit that exposes the raw data.

                            1 of 1 people found this helpful
                            • 11. Re: On/off radio button
                              peter.martin@sinclairdesign.com.au

                              Thank you. I found that two overlayed buttons each with appropriate Set Field and Hide values worked as required.

                              • 12. Re: On/off radio button
                                canoevalley

                                Hi Jade Nice button.

                                 

                                Nice button. I'm using them right now.If I have two or more of these buttons on a layout but only 1 can be on ant any one time, how would this be set up? I can't seem to figure this out using your coding.

                                 

                                If I have 2 or more of these buttons on a layout but only 1 can be on at any one time, how would this be set up? I can't seem to figure this out using your coding.

                                 

                                Thanks.

                                 

                                Bob

                                • 13. Re: On/off radio button
                                  Jade

                                  Hi Bob,

                                   

                                  The demo file uses only one field (Settings::g_Toggle).

                                   

                                  You will need to add more fields (one for each switch).  These can be added to your own table(s) or kept in Settings since they are defined as global fields in my demo.

                                   

                                  You must also change the Toggle script to handle multiple fields (or add another script for each switch).  I suggest you use just one script and pass the field (or number) to it using a script parameter so that it will update the field associated with each switch.

                                   

                                  Give it a try.  If you have a problem, let me know and I'll update the demo.

                                   

                                  br,

                                  Jon

                                   

                                  P.S.  I've made one design change since this was posted.  There is another background object which displays grey instead of green when the switch is in the "off" position.

                                  • 14. Re: On/off radio button
                                    canoevalley

                                    Thanks for the suggestion Jon. I'll work on this soon.  Will let you know If I succeed.

                                     

                                    I did update your toggle to turn grey on off.

                                     

                                    BTW, I noticed a few other toggle solutions here that use variables to achieve the same results as your toggle. Is there any benefit to this approach?

                                     

                                    Just an FYI.

                                     

                                    Thanks again.

                                     

                                    Bob

                                    1 2 Previous Next