![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
directus-extension-surveyjs
Advanced tools
Bundles a module and api endpoints Directus extenstions with SurveyJS to make the form creation and submission process easier
A Directus Module extension that integrates the SurveyJS Creator into Directus.
This extension allows you to create and manage surveys using the SurveyJS Creator directly within Directus. It provides a seamless interface for building, updating, and storing survey configurations.
After installation, the first time you will open the module page, you will be prompted with a form to finish the basic configuration.
The first field allows you to give the name to the collection that will be used to store all your form configurations. Default is form_configs
If you don't already have the languages
collection made by directus, make sure to create one.
languages
code
(String): Text.name
(String): Text.direction
(String): Text. https://github.com/user-attachments/assets/019e914a-3284-472c-a9a1-38c92ff33aec
Clicking the Finish setup
button will create the basic necessary collections for the creator to work.
Collections created :
Permissions:
form_configs
: READmodule_extension_survey_settings
: READ[form_submission_collection]
: CREATEThe translations available in the creator are based on the languages you have setup in your directus instance https://docs.directus.io/guides/headless-cms/content-translations.html#create-a-languages-collection
Module translations strings to add to your directus instance :
$t:extension_survey_form_creator
: Title used in the page navigation of the module "Form Creator"$t:extension_survey_no_forms
: Message displayed when no forms are found, should be something like "No forms available"$t:extension_survey_module_name
: Name of the module, should be something like "Forms"Handle default form creator form language:
Add a field M2O inside the module_extension_survey_settings
collection named default_form_language
.
From there, choose in the settings your default language.
The settings provide the default SurveyJS options available to the creator listed here https://surveyjs.io/survey-creator/documentation/api-reference/icreatoroptions
In addition, there is the licence_key
option that allows you to put your license for SurveyJS.
You can also add manually a field with the key default_form_language
M2O to languages
collection to handle the default form language
Activate the module by navigating to:
Settings -> Settings -> Modules
and enabling the Survey module.
form_configs
content object and assign it a friendly_id
.form_configs
content objects will be listed with their friendly_id
as the title.form_config
. The schema
should be updated with the new schema generated from the builder.languages
directus collection. So if you only have one language, your forms won't be translatable.Translations
tab of the builder. There you can add languages you wish to translate your forms in the left sidebar. For each language added, a new column will be added to translate every
string your form could contain.The extension provides several API endpoints for interacting with surveys. To access each route, you need to use the domain where your directus instance is hosted followed by /survey-api
followed by the route.
Example: https://directus-domain-example/survey-api/form-config-create
POST /form-submission/:formConfigId
formConfigId
: The ID of the form_configs
object.{'Content-Type': 'application/json'}
PATCH /form-config-update/:formConfigId
form_config
when saved inside the builder.POST /form-config-create
To handle form submissions, you need to create a collection that will be used as a type of submission.
Each form configuration accepts one type of form submission by passing it the name of the collection created in the field form_submission_collection
.
When submitting a form with this config, an entry will be created in that collection.
Example : If your form submission collection is called registrations
, your field should contain the exact name registrations
in your form_config's form_submission_collection field
This collection can take the name you wish. Add the fields you wish to collect data from the form. Examples :
You can use the Field Map in the form config to map fields created from SurveyJS to a field inside you form submission collection. If you use the same function to map your fields as the one used in the code example showed below, your mapping should look like the example below.
Example:
Data received from SurveyJS :
{
firstName: "John",
lastName: "Doe"
}
Field names in form submission collection:
{
first_name: Text,
last_name: Text
}
Your field map should look like
{
"first_name": "firstName",
"last_name": "lastName"
}
import { useCallback } from 'react'
import { Model } from 'survey-core'
import { Survey } from 'survey-react-ui'
import 'survey-core/defaultV2.min.css'
import 'survey-core/survey.i18n'
interface TDirectusSurveyProps {
formConfigId: string
schema: JsonObject
locale?: string
versionDate?: string
fieldMap?: JsonObject
additionalData?: JsonObject
}
type JsonValue = string | number | boolean | null | JsonObject | JsonArray
interface JsonObject {
[key: string]: JsonValue
}
type JsonArray = Array<JsonValue>
const DirectusSurvey = (props: TDirectusSurveyProps) => {
const { locale = 'default', schema, formConfigId, fieldMap, additionalData, versionDate } = props
const survey = new Model(schema)
survey.locale = locale
// Survey onComplete handler
const saveSurveyResults = (url: string, json: JSONObject) => {
const entriesFieldMap = Object.entries(fieldMap ?? {})
const mappedFields = entriesFieldMap
.map(([key, value]: string[]) => {
if (json?.[value]) {
return [key, json?.[value]]
}
return null
})
.filter((el) => el !== null)
const body = {
...Object.fromEntries(mappedFields),
...additionalData,
default_fields: {
form_data: {
...json,
...additionalData,
},
form_config: formConfigId,
form_language: locale,
form_config_version_date: versionDate,
},
}
fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json;charset=UTF-8',
},
body: JSON.stringify(body),
})
.then((response) => {
if (response.ok) {
// Handle success
} else {
// Handle error
}
})
.catch((error) => {
// Handle error
})
}
const handleComplete = useCallback((form: Model) => {
saveSurveyResults(`{{ your domain here }}/survey-api/form-submission/${formConfigId}`, form.data)
}, [])
survey.onComplete.add(handleComplete)
return <Survey model={survey} />
}
export default DirectusSurvey
Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes.
This project is licensed under the MIT License. See the LICENSE file for details.
Feel free to contribute or suggest improvements!
FAQs
Bundles a module and api endpoints Directus extenstions with SurveyJS to make the form creation and submission process easier
The npm package directus-extension-surveyjs receives a total of 4 weekly downloads. As such, directus-extension-surveyjs popularity was classified as not popular.
We found that directus-extension-surveyjs demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.