How do I use a built in form?
There are 3 possible form actions
- Run - shows the form in a dialog
- Set - sets the values to be displayed on the form before it is shown
- Get - fetches the values entered into the form after it has been shown
Each form is made up of a number of controls, which you can refer to by number.
The form we will be using, LCRating, has 2 controls.
Control 2, the slider is the one we are interested in.
Forms allows you to create customer user input dialog windows. LiveCode for FM comes with a number of built in forms that you can use immediately. You can also make copies of the built in forms which you can then edit, or create your own forms from scratch.
In this lesson we'll see how to use one of the built in forms, LCRating, in your FileMaker solution.
I have created a FileMaker solution, which shows the rating, title and author of the top 100 books from the BBC Big Read project. I have added a 'rating' field so I can keep track of my personal rating for the books.
I have added a button next to this field, which will show the LCRating form and set the 'Rating' field in the database with the chosen value.
The first action we will learn about is the Run action, which shows the dialog.
Form components are used via the LC plugin function, you pass the form name, action and any additional parameters to the LC function.
To show the form we add a FileMaker script to the button.
Open the Button Setup and set the Action to 'Perform Script'.
Add a new script and name it 'rate book'
- Add a step - Set Variable
- Set the name to 'rate'
- Set the value to LC("LCRating.Run")
- Click "OK"
This calls the LC API function passing the form name, 'LCRating', and the action, 'Run'.
Leave the Layout Editing mode and try clicking the 'Rate' button. The LCRating form is shown.
Click "OK" to dismiss the dialog.
When you show the LCRating form it would be ideal to show the current rating value in the slider. We can do this using the Set action.
The Set action allows you to set the values in the fields defined on the form before showing it:
LC ( "<component-name>.Set" ; <field-index> ; <field-value> )
To do this we'll add a second step to the FileMaker script, which is run before the form is shown.
Remember the slider is control 2 so that is the value we want to set.
Open the "rate book" script and add a line before the Run step. Add a second 'Set Variable' step, which calls the Set action for the LCRating from and sets the value of control 2(the slider) to the value of the 'Rating' field in FileMaker.
Leave the Layout Editing mode, set a value in the 'Rating' field and click the 'Rate' button.
The form will be shown with the slider set to the current value.
The final step is to update the 'Rating' field with the value the user selects in the form.
The Get action allows you to fetch the values the user chose after showing it:
LC ( "<component-name>.Get" ; <field-index> )
To do this we add a third step to the FileMaker script, which is run after the form has been closed.
Open the "rate book" script and add a line after the Run step. Add a second 'Set Field' step, which calls the Get action for the LCRating from, returns the value of control 2(the slider) and updates 'Rating' field in FileMaker.
Leave the Layout Editing mode, set a value in the 'Rating' field and click the 'Rate' button. Change the value on the slider and click "OK".
The 'Rating' field will be updated with the value chosen on the slider.