-
Notifications
You must be signed in to change notification settings - Fork 26
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 #3552 from open-formulieren/issue/2629-dynamic-opt…
…ions Confirm ability to use dynamic options in selectboxes
- Loading branch information
Showing
11 changed files
with
300 additions
and
5 deletions.
There are no files selected for viewing
Binary file not shown.
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 |
---|---|---|
@@ -0,0 +1,125 @@ | ||
.. _example_logic_dynamic_options_3: | ||
|
||
========================================================================== | ||
Formulier met (extra) opties in selectievakjes, keuzelijst en radio-velden | ||
========================================================================== | ||
|
||
In dit voorbeeld maken we een deel-formulier waarbij een vaste groep keuzeopties | ||
dynamisch uitgebreid wordt op basis van logica-regels. | ||
|
||
Deze functionaliteit kan op eenzelfde manier worden gebruikt voor de "radio"-, | ||
"keuzelijst"- en de "selectievakjes"-componenten. | ||
|
||
.. note:: | ||
|
||
U kunt dit voorbeeld downloaden en :ref:`importeren <manual_export_import>` | ||
in Open Formulieren. | ||
|
||
Download: :download:`dynamische-keuzelijsten.zip <_assets/dynamische-keuzelijsten.zip>` | ||
|
||
Formulier maken | ||
=============== | ||
|
||
#. Maak een formulier aan met de volgende gegevens: | ||
|
||
* **Naam**: Dynamische keuzelijsten | ||
|
||
#. Klik op het tabblad **Variabelen**. Klik hierbinnen op het tabblad | ||
**Gebruikersvariabelen**. | ||
|
||
#. Voeg een variabele toe door op **Variabele toevoegen** link te klikken, en voer in: | ||
|
||
* **Naam**: Checkbox options | ||
* **Datatype**: Lijst (array) | ||
* **Beginwaarde**: vink *"Gebruik ruwe JSON-invoer"* aan en voer de JSON-array in: | ||
|
||
.. code-block:: json | ||
[ | ||
[ | ||
"option1", | ||
"Option 1" | ||
], | ||
[ | ||
"option2", | ||
"Option 2" | ||
] | ||
] | ||
#. Klik op het tabblad **Stappen en velden**. | ||
|
||
#. Klik aan de linkerkant op **Stap toevoegen** en selecteer **Maak een nieuwe | ||
formulierdefinitie**. | ||
|
||
#. Onder de sectie **(Herbruikbare) stapgegevens** vul het volgende in: | ||
|
||
* **Naam**: Variabele selectievakjesopties | ||
|
||
#. Scroll naar de sectie **Velden**. | ||
|
||
#. Sleep een **Selectievakje** component op het witte vlak, vul de volgende | ||
gegevens in en druk daarna op **Opslaan**: | ||
|
||
* **Label**: Toon optie 3 | ||
|
||
#. Sleep een **Selectievakjes** component op het witte vlak, vul de volgende | ||
gegevens in en druk daarna op **Opslaan**: | ||
|
||
* **Label**: Variabele opties selectievakjes | ||
* **Beschrijving**: De beschikbare opties zijn afhankelijk van eerdere antwoorden. | ||
|
||
* **Keuzeopties**: *Variabele* | ||
* **Opties-expressie**: | ||
|
||
.. code-block:: json | ||
{ | ||
"var": "checkboxOptions" | ||
} | ||
Deze referentie komt overeen met de sleutel van de eerder toegevoegde | ||
gebruikersvariabele. | ||
|
||
#. Klik op het tabblad **Logica** en voeg een eenvoudige regel toe. | ||
|
||
#. Kies als triggervoorwaarde: | ||
|
||
* Als "Variabele selectievakjesoptie: Toon optie 3 (toonOptie3)" | ||
* "is gelijk aan" | ||
* "de waarde" | ||
* "Ja" | ||
|
||
#. Voeg een actie toe: | ||
|
||
* dan "zet de waarde van een variabele/component" | ||
* "Checkbox options (checkboxOptions)" | ||
* voer de volgende JsonLogic in: | ||
|
||
.. code-block:: json | ||
{ | ||
"merge": [ | ||
{ | ||
"var": "checkboxOptions" | ||
}, | ||
[ | ||
[ | ||
"option3", | ||
"Option 3" | ||
] | ||
] | ||
] | ||
} | ||
#. Klik onderaan op **Opslaan** om het formulier volledig op te slaan. | ||
|
||
U kunt nu het formulier bekijken. | ||
|
||
.. note:: | ||
|
||
Deze expressie gebruik de JsonLogic `merge`_ operatie om de bestaande | ||
gebruikersvariabele uit te breiden met extra keuzeopties. U kunt vrij | ||
gebruikersvariabelen combineren zolang de variabele voor de selectievakjes component | ||
een lijst van opties (waarde en label) bevat. | ||
|
||
.. _merge: https://jsonlogic.com/operations.html#merge |
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
76 changes: 76 additions & 0 deletions
76
src/openforms/js/components/admin/form_design/logic/LiteralValueInput.stories.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,76 @@ | ||
import {FormDecorator} from '../story-decorators'; | ||
import LiteralValueInput from './LiteralValueInput'; | ||
|
||
export default { | ||
title: 'Form design / LiteralValueInput', | ||
component: LiteralValueInput, | ||
decorators: [FormDecorator], | ||
args: { | ||
name: 'aValue', | ||
type: 'string', | ||
value: undefined, | ||
}, | ||
}; | ||
|
||
export const Text = { | ||
name: 'String', | ||
args: { | ||
type: 'string', | ||
}, | ||
}; | ||
|
||
export const NumFloat = { | ||
name: 'Float', | ||
args: { | ||
type: 'float', | ||
}, | ||
}; | ||
|
||
export const NumInt = { | ||
name: 'Int', | ||
args: { | ||
type: 'int', | ||
}, | ||
}; | ||
|
||
export const DateTime = { | ||
args: { | ||
type: 'datetime', | ||
}, | ||
}; | ||
|
||
export const Date_ = { | ||
name: 'Date', | ||
args: { | ||
type: 'date', | ||
}, | ||
}; | ||
|
||
export const Bool = { | ||
name: 'Boolean', | ||
args: { | ||
type: 'boolean', | ||
}, | ||
}; | ||
|
||
export const Arr = { | ||
name: 'Array', | ||
args: { | ||
type: 'array', | ||
}, | ||
}; | ||
|
||
export const ArrWithValues = { | ||
name: 'Array with values', | ||
args: { | ||
type: 'array', | ||
value: ['Item 1', 'Item 2'], | ||
}, | ||
}; | ||
|
||
export const Obj = { | ||
name: 'Object', | ||
args: { | ||
type: 'object', | ||
}, | ||
}; |
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
49 changes: 49 additions & 0 deletions
49
src/openforms/js/components/admin/form_design/variables/VariablesEditor.stories.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,49 @@ | ||
import {FormDecorator} from '../story-decorators'; | ||
import VariablesEditor from './VariablesEditor'; | ||
|
||
export default { | ||
title: 'Form design / Variables editor', | ||
component: VariablesEditor, | ||
decorators: [FormDecorator], | ||
args: { | ||
variables: [ | ||
{ | ||
form: 'http://localhost:8000/api/v2/forms/36612390', | ||
formDefinition: 'http://localhost:8000/api/v2/form-definitions/6de1ea5a', | ||
name: 'Form.io component', | ||
key: 'formioComponent', | ||
source: 'component', | ||
prefillPlugin: '', | ||
prefillAttribute: '', | ||
prefillIdentifierRole: 'main', | ||
dataType: 'string', | ||
dataFormat: undefined, | ||
isSensitiveData: false, | ||
serviceFetchConfiguration: undefined, | ||
initialValue: '', | ||
}, | ||
{ | ||
form: 'http://localhost:8000/api/v2/forms/36612390', | ||
formDefinition: undefined, | ||
name: 'User defined', | ||
key: 'userDefined', | ||
source: 'user_defined', | ||
prefillPlugin: '', | ||
prefillAttribute: '', | ||
prefillIdentifierRole: 'main', | ||
dataType: 'array', | ||
dataFormat: undefined, | ||
isSensitiveData: false, | ||
serviceFetchConfiguration: undefined, | ||
initialValue: [], | ||
}, | ||
], | ||
}, | ||
argTypes: { | ||
onChange: {action: true}, | ||
onAdd: {action: true}, | ||
onDelete: {action: true}, | ||
}, | ||
}; | ||
|
||
export const Default = {}; |
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