MembersWithDB.fdf (2.9 MB)
MembersApp.fdf (2.9 MB)
Hi RMittelman
The way you are choosing to do it is the efficient way for storage in the database. I would do how you are suggesting.
I have attached two FDFs, both have three tables Member, MemberGroup and a join table of MemberGroupJoin.
The MembersWithDB.fdf shows you how every field on the Member Groups form is attached to the database, no code is required, however it can’t be stored in the database as you are suggesting as all the Week fields are attached to the database. And you were correct in making the fields booleans so they could just be turned on.
I think you have this method under control, but I have attached the FDF so you can compare the two.
The MembersApp.fdf shows how you can show the boolean fields on a form, but, store the data as you want in the database.
Please follow the following steps:
-
Import and run the MembersApp.fdf.
-
Select Members Group in the menu.
-
Either edit one of the records there or add a new one and click some of the week switches on.
-
Click the Save button in the form app bar. (You will see here the storage that you are after is entered into the Weeks field.)
The following steps will show how you can do this in Five.
-
Go back into Five.
-
Navigate to the Forms view under the Visual menu and select the Member Groups form.
-
Navigate to the field records by clicking the Pages tab, selecting the General record and clicking the fields tabs. (Here you will see there is a Weeks field, if you select it you will see it is attached to the database, you can tell this by the value in the Fields field, this is selecting a field from the table in the database.)
- Click the back button and select the Week 1 record. (You will see here this field is not attached the database as there is no field selected in the Field field. So whatever data is entered into this field will not be stored in the database. All the other Week fields are set up the same. If you go to the table view you will see these fields do not exist in the table.)
Two functions are involved to do this.
-
Navigate to the Functions view under the Logic menu. These two functions are used.
-
Click in the Code field to open the editor.
In these functions you will see how the DisplayWeeks function turns on or off the Week switches automatically using bitwise operations using the Weeks field from the database and the opposite in the SaveWeeks function.
These functions are attached to events on the Member Groups form.
- Navigate back to the Member Groups form and click the Events tab.
The DisplayWeeks function will execute on show, on editing and on canceling the form record.
The SaveWeeks function will execute on completion of the form.
Tips:
On events are client-side, Do events are server-side.
Clicking the VIEW button will take you straight to the code in our large code editor.
One tip I can give you is you probably do not want to display the Weeks field on the your form as this is just for your storage in the database. To hide this field on your form follow the steps below.
-
Navigate to the field records again on the Members Group form.
-
Select the Weeks field.
-
Click the Display tab.
-
In the Show If field type false. (Must be all lower case as the If fields take a JavaScript statement.) Now the field will be hidden on the form and the data is being stored how you want.
There is a third option by writing a field plugin.
I hope this helps you achieve your requirements.