-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1108 from facebookresearch/form-builder-code-inse…
…rtions Enabled custom code insertions for FormComposer
- Loading branch information
Showing
74 changed files
with
16,346 additions
and
2,774 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
version: 2 | ||
|
||
updates: | ||
# Maintain dependencies for GitHub Actions | ||
- package-ecosystem: "github-actions" | ||
directory: "/" | ||
schedule: | ||
interval: "weekly" | ||
labels: | ||
- "dependencies" | ||
# ignore all patch version updates | ||
ignore: | ||
- dependency-name: "*" | ||
update-types: ["version-update:semver-patch"] | ||
|
||
# Maintain dependencies for npm | ||
- package-ecosystem: "npm" | ||
directory: "/" | ||
schedule: | ||
interval: "weekly" | ||
labels: | ||
- "dependencies" | ||
# ignore all patch version updates | ||
ignore: | ||
- dependency-name: "*" | ||
update-types: ["version-update:semver-patch"] | ||
|
||
# Maintain dependencies for pip | ||
- package-ecosystem: "pip" | ||
directory: "/" | ||
schedule: | ||
interval: "weekly" | ||
labels: | ||
- "dependencies" | ||
# ignore all patch version updates | ||
ignore: | ||
- dependency-name: "*" | ||
update-types: ["version-update:semver-patch"] | ||
|
||
# Maintain dependencies for Docker | ||
- package-ecosystem: "docker" | ||
directory: "/" | ||
schedule: | ||
interval: "weekly" | ||
labels: | ||
- "dependencies" | ||
# ignore all patch version updates | ||
ignore: | ||
- dependency-name: "*" | ||
update-types: ["version-update:semver-patch"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,5 @@ AWS_SECRET_ACCESS_KEY=... | |
AWS_DEFAULT_REGION=... | ||
|
||
S3_URL_EXPIRATION_MINUTES=60 | ||
|
||
CYPRESS_CACHE_FOLDER=/tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
examples/form_composer_demo/data/dynamic/insertions/about_section_items.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<ul> | ||
<li>Background</li> | ||
<li>Personal information</li> | ||
<li>Etc</li> | ||
</ul> |
55 changes: 55 additions & 0 deletions
55
examples/form_composer_demo/data/dynamic/insertions/custom_triggers.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// NOTE: that `react-form-composer` library must be set in webpack config as an alias. | ||
import { validateFieldValue } from "react-form-composer"; | ||
|
||
export function onChangeCountry( | ||
formData, // React state for the entire form | ||
updateFormData, // callback to set the React state | ||
element, // "field", "section", or "submit button" element that invoked this trigger | ||
fieldValue, // (optional) current field value, if the `element` is a form field | ||
formFields, // Object containing all form fields as defined in 'form_config.json' | ||
...args // Arguments for this trigger (taken from form config) | ||
) { | ||
// By default, `id_section_second` section is collapsed, and `id_region` field is hidden. | ||
// Selecting "USA" in `id_country` should open that section, and display that field. | ||
const secondSectionElement = document.getElementById("id_section_second"); | ||
const regionFieldElement = document.getElementById("id_region"); | ||
|
||
if (fieldValue === "USA") { | ||
// Open `id_section_second` section | ||
secondSectionElement.classList.add("hidden"); | ||
|
||
// If you want to check (during development) that you're assigning a valid value to a field, | ||
// use `validateFieldValue` function from form composer utils (see the import above). | ||
const newMottoValueIsValid = validateFieldValue(formFields.motto, "", true); | ||
if (!newMottoValueIsValid) { | ||
console.log( | ||
"Write additional log message or logic here " + | ||
"if logs with argument `writeConsoleLog` is not enough for you" | ||
); | ||
} | ||
|
||
updateFormData("motto", ""); // Clear field value in React state | ||
|
||
// Show `id_region` field | ||
regionFieldElement.closest(".field").classList.remove("hidden"); | ||
} else { | ||
// Collapse `id_section_second` section | ||
secondSectionElement.classList.remove("hidden"); | ||
|
||
// Hide `id_region` field | ||
regionFieldElement.closest(".field").classList.add("hidden"); | ||
updateFormData("region", ""); // Clear field value in React state | ||
} | ||
} | ||
|
||
export function onClickSectionHeader( | ||
formData, // React state for the entire form | ||
updateFormData, // callback to set the React state | ||
element, // "field", "section", or "submit button" element that invoked this trigger | ||
fieldValue, // (optional) current field value, if the `element` is a form field | ||
formFields, // Object containing all form fields as defined in 'form_config.json' | ||
sectionName // Argument for this trigger (taken from form config) | ||
) { | ||
// Do something when header is clicked (toggle a section content) | ||
alert(`${sectionName} section title clicked.`); | ||
} |
23 changes: 23 additions & 0 deletions
23
examples/form_composer_demo/data/dynamic/insertions/custom_validators.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const FORBIDDEN_WORDS = ["fool", "silly", "stupid"]; | ||
|
||
export function checkForbiddenWords(field, value, check) { | ||
if (!check) { | ||
return null; | ||
} | ||
|
||
let invalid = false; | ||
|
||
FORBIDDEN_WORDS.forEach((word) => { | ||
if (value.includes(word)) { | ||
invalid = true; | ||
} | ||
}); | ||
|
||
if (invalid) { | ||
return `Field cannot contain any of these words: ${FORBIDDEN_WORDS.join( | ||
", " | ||
)}.`; | ||
} | ||
|
||
return null; | ||
} |
10 changes: 10 additions & 0 deletions
10
examples/form_composer_demo/data/dynamic/insertions/form_instruction.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<div class="instruction"> | ||
Please answer <b>all</b> questions to the best of your ability as part of our | ||
study. | ||
</div> | ||
|
||
<style> | ||
.instruction { | ||
font-style: italic; | ||
} | ||
</style> |
1 change: 1 addition & 0 deletions
1
examples/form_composer_demo/data/dynamic/separate_token_values_config.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
{ | ||
"company_name": ["Facebook", "Mephisto"], | ||
"about_section_items": ["insertions/about_section_items.html"], | ||
"since_age": [18] | ||
} |
Oops, something went wrong.