Using field plug-ins
While every SurveyCTO field type has a standard way of appearing, operating, and being configured, the text, integer, decimal, select_one, and select_multiple field types also support field plug-ins. These plug-ins can extend or change the appearance, functionality, and customizability of the standard field types, in order to meet different needs. You can use field plug-ins that other people develop and share, or you can develop your own.
To use a field plug-in, you need to do two things:
- Attach the field plug-in to your form.
- Select the field plug-in at the appropriate field(s).
Attaching a field plug-in to a form
Attach the “[name].fieldplugin.zip” file to your form. If you're using the online Form Designer to edit your form, you can attach a field plug-in by opening Form settings and scrolling down to the Attachments section. You may also attach a field plug-in while editing a field's appearance option (see below).
If you're uploading spreadsheet form definitions, you can attach it just like you would do with any other form attachment (like attached .csv files or images).
Selecting a field plug-in at a field
If you're using the online Form Designer, when editing a field, scroll down to the appearance setting in the Other options section. If you select the Use a field plug-in to render this field checkbox, you will see a dropdown list of all the available field plug-ins that are attached to your form and support the current field type. If none are available, you can select the Add new field plug-in option and attach a new one.
If you're manually editing the spreadsheet form definition, you can specify the field plug-in to use in the appearance column of a field. For each field that should use your plug-in, set the field’s appearance to “custom-[plug-in name]”.
custom-myplugin in the appearance column for each field that should use it.
What to expect
Please keep in mind, when you use a field plug-in, that plug-in will completely take over the appearance of a field. Make sure you trust the developer before you use their field plug-in and, as always, perform adequate testing before you deploy your form. Some other things to keep in mind:
- A field plug-in may not support your current appearance options. Check the developer's documentation to see what options are supported before you attach it to your form, and test it thoroughly before you start actually collecting data.
- The "Label display behavior" setting (in Collect's Admin Settings) will have no effect on a field plug-in.
- When using SurveyCTO Collect on iOS, the on-screen keyboard may not automatically appear when you arrive on a field that uses a field plug-in. In that case, you will simply need to press once on the actual input field and the on-screen keyboard should appear.
Map plug-ins: touch gestures and device location
Field plug-ins that show a map, or anything else you drag, pinch, or press, can work much like a map in any other app:
- Touch gestures. A field plug-in can ask to keep the touch gestures that start inside it. Then dragging, swiping, or long-pressing inside the plug-in moves the map instead of scrolling the form, moving to another screen, or opening the field's menu. To scroll the form, drag outside the plug-in, so when you test your form, check on your smallest devices that part of the screen stays outside the plug-in. Field plug-ins that don't ask for this behave as before. Check the plug-in's documentation to see whether it does.
- Device location. A field plug-in can show the device's current location, for example as a dot on the map, when SurveyCTO Collect already has permission to use the location. Collect never asks for that permission on a plug-in's behalf: without it, the plug-in simply can't see the location. In web forms, the browser asks the respondent for permission, as it does on any website.
Parameters
Some field plug-ins will accept or even require parameters. Each field plug-in can have slightly different requirements with regard to parameters, so be sure to read the developer's documentation carefully.
If you're using the online Form Designer, adding parameters is easy. Once you've selected a field plug-in in the appearance section, you will see an input box labeled Plug-in parameters. Enter a comma-separated list of parameters according to the requirements of the field plug-in.
min and max parameters; in that case, you could enter "min=0, max=10" in the box. If the same field plug-in accepts an optional parameter for color, you might enter "min=0, max=10, color='blue'".
If you're manually editing the spreadsheet form definition, you can specify parameters when you specify the field plug-in in the appearance column. Add a comma-separated list of parameters after the plug-in name, enclosed by parentheses.
min and max, your appearance column could look like this: "custom-slider(min=0, max=10)".
Note: parameters can evaluate expressions and field references. So if you want to define a parameter's value based on the response from a previous field, you could do something like this: "min=0, max=${field}".
Camera and photos
Field plug-ins can use the device camera, in SurveyCTO Collect for Android (starting with version 2.86.0), SurveyCTO Collect for iOS, and web forms. In Collect for Android, the camera permission is requested together with the other permissions when Collect first starts. A field plug-in can also show or process a photo that another image field in the same submission took: pass the other field to the plug-in as a parameter, such as "custom-myplugin(photo=${img})", if the plug-in's documentation says it supports this. Plug-ins can display and analyze the photo but cannot save a photo as their own answer.
If you're developing a field plug-in, see the API reference for how to use the camera (getUserMedia) and the getSubmissionFileUrl function.
Developing your own field plug-ins
If you're interested in developing your own field plug-ins, please see the developer documentation.