DataControl
Example
<div
id="data_control_test"
data-hf-control="DataControl"
data-hf-options="{
defaultValue: {
testEntry: 'test'
},
onChanged: HFFormdefinition.Namespace.Method
}"
></div>
Note
The DataControl is a hidden control that can be used to store data in the Form. The data is stored in the Form as a JSON string.
FormControl Options​
defaultValue​
Provide a default object for the control. A Custom Code function can be used to set defaultValue.
How to use:
defaultValue: { testEntry: 'testValue' }
Type:
object | function
Signature:
function() => object
doNotCopy​
Set "true" whenever the field should get deleted if the Form is copied.
How to use:
doNotCopy: true
Type:
boolean
onChanged​
Call a pre-defined JS-method to do something when the status of the control changes.
How to use:
onChanged: HFFormdefinition.Namespace.Method
Type:
function
Signature:
function(value: object) => void
persistent​
It is the value where the "user" sets the initial value of the DataControl to the value of the previous Form item of the current user and overwrites any defaultValue.
How to use:
persistent: 'user'
Type:
'user'
copyValueFrom​
Define a FormControl that synchronizes its value with the current field. This synchronization process occurs upon navigating to the page where the current control is situated. It only occurs if the field is empty or the mode is set to "overwrite".
<div
id="data_control_test"
data-hf-control="DataControl"
data-hf-options="{
copyValueFrom: 'data_control_test_copy'
}"
></div>
Option interface
interface ICopyValueFromObject {
sourceId: string;
mode: 'overwrite' | null;
callback: (value: string) => string;
}
type CopyValueFromType = string | ICopyValueFromObject;
callback​
Specify a function to process value before copy.
How to use:
callback: HFFormDefinition.Namespace.processValue
Type:
function
Signature:
function(value: string) => string
mode​
Specify if target field gets overwritten. Default behaviour is to only copy to empty fields.
How to use:
mode: 'overwrite'
Type:
string
Stored data
​The simplest storage – ID and the filled-in stringified value:
{
"id": "data_control_test",
"value": "{\"testEntry\":\"test\"}"
}