Add Custom JavaScript
2 minutes to readEach DataPart in a Flex app can have its own custom JavaScript. Use it to add behavior that the built-in settings don’t cover, such as highlighting report rows based on a value, changing form data before it is submitted, or stopping a submission that fails your own rules. Your script listens for events that Caspio fires as the app runs, such as when a DataPart finishes loading or when a form is about to be submitted.
You can write the script yourself, or describe what you want and let Caspi write it.
Add custom JavaScript to a DataPart
- In your Flex app, select Designer.
- On the canvas, select the DataPart.
- In the right panel, under Customization, select Set Custom JavaScript.
- In the editor, enter your JavaScript. Enter plain JavaScript without
<script>tags. - To refer to a DataPart or an AppPage, select Insert parameter instead of typing its ID.
- Select Save, and then select Close.
Refer to DataParts and AppPages
Scripts identify the DataPart or AppPage they work with by its ID. Instead of typing the ID, insert a parameter. Caspio replaces the parameter with the real ID when the DataPart renders, so the script keeps working after you rename objects or move the app to another account.
- In the editor, place the cursor where the parameter goes, and then select Insert parameter.
- In Type, select DataPart ID or AppPage ID.
- In Parameter, select an AppPage in the current Segment. For a DataPart ID, then select a DataPart on that AppPage. The current DataPart is selected by default.
- Select Insert.
Generate custom JavaScript with Caspi
Describe the behavior you want, and Caspi writes the JavaScript for the DataPart and adds it once you approve it.
- Open the DataPart’s Custom JavaScript editor.
- Select Ask Caspi.
- Describe the behavior, for example: “Color rows green when Amount is over 100.”
- Review the proposed script, and then approve it.
- Review the script in the editor, and then select Save.