Dynamic Repeating Units
Dynamic repeating units function similarly to standard repeating units, as a repeatable set of controls at the tab level. However, with dynamic repeating units, each repeating unit is generated based on a provided data source. This allows you to create repeating sets of data corresponding to the rows of a data source.
In the HTML block templates, you can use special placeholders {{$.[PLACEHOLDER]}}
to reference values from the data source. Once the dynamic repeating unit is generated,
the placeholders are replaced with the corresponding values from the data source and then saved.
To define a dynamic repeating unit, use the dynamicRepeatingUnit
property within the data-hf-repeating
attribute.
As with standard repeating units, it is mandatory to set the id attribute on the tab.
HTML Definitionβ
<li
id="dynamic-ru-tab-01"
data-hf-title="Dynamic RU Automatic"
data-hf-repeating='{
"dynamicRepeatingUnit": {
"source": "{{HFFormPath}}/InventoryDB.json",
"trigger": "automatic",
"filter": "HFFormdefinition.Playground.filterDynamicRUDataSource"
}
}'
>
<a href="#block_tab_dru_1"></a>
<a href="#block_tab_dru_2"></a>
</li>
<li
id="dynamic-ru-tab-02"
data-hf-title="Dynamic RU Manual"
data-hf-repeating='{
"dynamicRepeatingUnit": {
"source": "/api/catalogs/InventoryDB",
"trigger": "manual",
"filter": "HFFormdefinition.Playground.filterDynamicRUDataSource",
"onFinished": "HFFormdefinition.Playground.onFinishDynamicRU"
},
"header": ["repeating1HeaderBlock1", "repeating1HeaderBlock2"]
}'
>
<a href="#block_tab_dru_3" data-hf-fullWidth="true"></a>
</li>
Options for Dynamic Repeating Unitsβ
Dynamic-Repeating-Unit Optionsβ
Use the dynamic-repeating-unit
property to define the repeating unit as dynamic. These are the options available
for the dynamic repeating unit object within the data-hf-repeating
attribute. The object must be provided as valid
JSON.
source - requiredβ
string | array
trigger - requiredβ
string
filterβ
string
onFinishedβ
string
Standard Repeating-Unit Optionsβ
These are the options available from the standard repeating units defined on the data-hf-repeating
attribute.
Provide the object as a valid JSON.
alwaysShowHeaderFooterβ
"alwaysShowHeaderFooter"=true
string
anchorsβ
"anchors"=false
boolean
footerβ
"footer"=[repeating1FooterBlock1, repeating1FooterBlock2]
string
headerβ
"header"=[repeating1HeaderBlock1, repeating1HeaderBlock2]
string
orderβ
"order"="desc"
boolean
If you use the option alwaysShowHeaderFooter: false
to hide the header and footer, you cannot use the required: true
option inside those blocks.
Using Data Source Values (with Placeholders)β
In the HTML block templates, special placeholders{{$.[PLACEHOLDER]}}
can be used to reference values in the data source. The *PLACEHOLDER is the key corresponding to a value in the data source.
<div id="block_tab_dru_1" data-hf-block>
<div class="grid column3">
<div class="r1 c1">
<input
id="tf_dru_01"
type="text"
data-hf-control="HFWinJSCtrl.TextField"
data-hf-options="{
label: '{{$.Description}}'
}"
/>
</div>
<div class="r1 c2">
<input
id="tf_dru_02"
type="text"
data-hf-control="HFWinJSCtrl.TextField"
data-hf-options="{
label: 'In Stock',
defaultValue: '{{$.Stock}}'
}"
/>
</div>
<div class="r1 c3">
<div
id="id_numericfield01"
data-hf-control="HFWinJSCtrl.NumericField"
data-hf-options="{
label: 'Price',
defaultValue: {{$.Price}},
disabled: true
}"
></div>
</div>
</div>
</div>
<div id="dynamic-ru-tab-02" data-hf-block>
<div class="grid column6">
<div class="r1 c1 cspan2">{{$.Description}}</div>
<div class="r1 c3">{{$.Title}}</div>
<div class="r1 c4">{{$.Stock}}</div>
<div class="r1 c5">{{$.Price | function: HFFormDefinition.Playground.addVAT}}</div>
<div class="r1 c6">
<input
id="id_checkbox01"
type="checkbox"
value="value"
data-hf-control="HFWinJSCtrl.CheckBox"
data-hf-options="{
label: 'Get it!',
defaultValue: false,
style: 'backgroundHighlight',
}"
/>
</div>
</div>
</div>
Using Pipesβ
You can use pipes to format data source values. A pipe is a function defined in the global scope of the form definitionβs Custom Code. The pipe function receives the data source value as the first argument and the corresponding data source item as the second argument. The functionβs return value is used for the placeholder.<div class="r1 c5">{{$.Price | function: HFFormDefinition.Playground.addVAT}}</div>
export function addVAT(value, dataItem) {
const price = parseFloat(value) * 1.2; // + 20% VAT
return price.toString();
}
Manually Initialize Dynamic Repeating Unitβ
You can manually invoke a dynamic repeating unit by calling theinitializeDynamicRepeatingUnit
method on the
HybridForms.API.RepeatingUnit object. Pass the tab ID of the repeating unit as the first argument.
- TypeScript
- HTML
export function initializeDynamicRepeatingUnit() {
HybridForms.API.RepeatingUnits.initializeDynamicRepeatingUnit('dru_tab_01').then(() => {
console.log('CustomCode.initializeDynamicRepeatingUnit(): Dynamic RU initialized');
});
}
<li id="dru_tab_01"
data-hf-title="dRU 01"
data-hf-repeating='{
"dynamicRepeatingUnit": {
"source": "/api/catalogs/InventoryDB",
"trigger": "manual",
"filter": "HFFormdefinition.CustomCode.filterDynamicRUDataSource",
"onFinished": "HFFormdefinition.CustomCode.onFinishDynamicRU"
},
"header": ["dru_headerBlock1", "dru_headerBlock2"]
}'>
<a href="#block_tab_dru_3"
data-hf-fullwidth="true"></a>
</li>