Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.

Commit d1e955d

Browse files
authored
Merge pull request #8536 from DashukVolodymyr/row-builder-add-with-data
magento/devdocs#: Added rowbuilder info
2 parents ab857fb + 42eb2b6 commit d1e955d

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed

src/guides/v2.3/javascript-dev-guide/widgets/widget-row-builder.md

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,94 @@ The following example shows a PHTML file using the script:
5454
</script>
5555
```
5656

57+
The following example shows a PHTML file using the script with some data for a couple of fields:
58+
59+
```html
60+
<div class="row-builder-example">
61+
<div id="max-rows-message" style="display: none;" class="message notice limit" role="alert">
62+
<span>Number of rows exceeded.</span>
63+
</div>
64+
<button type="button" id="add-row-button" class="action add">
65+
<span>Add Item</span>
66+
</button>
67+
<div id="row-container"></div>
68+
</div>
69+
70+
<script id="row-template" type="text/x-magento-template">
71+
<div>
72+
<div class="field name required">
73+
<label for="field1-name<%- data._index_ %>" class="label"><span>Item <%- data._index_ %> Field</span></label>
74+
<div class="control">
75+
<input name="field1[name][<%- data._index_ %>]" type="text" title="<?= $block->escapeHtmlAttr(__('Name')) ?>" class="input-text"
76+
id="field1-name<%- data._index_ %>"/>
77+
</div>
78+
</div>
79+
<div class="field name required">
80+
<label for="field2-name<%- data._index_ %>" class="label"><span>Item <%- data._index_ %> Field</span></label>
81+
<div class="control">
82+
<input name="field2[name][<%- data._index_ %>]" type="text" title="<?= $block->escapeHtmlAttr(__('Name')) ?>" class="input-text"
83+
id="field2-name<%- data._index_ %>"/>
84+
</div>
85+
</div>
86+
<div class="field name required">
87+
<label for="field3-name<%- data._index_ %>" class="label"><span>Item <%- data._index_ %> Field</span></label>
88+
<div class="control">
89+
<input name="field3[name][<%- data._index_ %>]" type="text" title="<?= $block->escapeHtmlAttr(__('Name')) ?>" class="input-text"
90+
id="field3-name<%- data._index_ %>"/>
91+
</div>
92+
</div>
93+
<div class="actions-toolbar">
94+
<div class="secondary">
95+
<a href="#" id="btn-remove<%- data._index_ %>" class="action remove"
96+
title="Remove Item">
97+
<span>Remove Item</span>
98+
</a>
99+
</div>
100+
</div>
101+
</div>
102+
</script>
103+
104+
<script>
105+
require([
106+
'jquery',
107+
'rowBuilder'
108+
], function ($) {
109+
'use strict';
110+
111+
var data = {
112+
formData: [
113+
["field1-name1", "field2-name1", "field3-name1"],
114+
["field1-name2", "field2-name2", "field3-name2"],
115+
["field1-name3", "field2-name3", "field3-name3"],
116+
["field1-name4", "field2-name4", "field3-name4"],
117+
],
118+
templateFields: [
119+
"field1-name", "field2-name", "field3-name"
120+
]
121+
};
122+
123+
$(".row-builder-package-manager").rowBuilder({
124+
"rowTemplate": "#row-template",
125+
"rowContainer": "#row-container",
126+
"rowParentElem": "<div></div>",
127+
"remEventSelector": "a",
128+
"btnRemoveSelector": ".action.remove",
129+
"formDataPost": data
130+
});
131+
});
132+
</script>
133+
```
134+
135+
This is provided during widget instantiation. For example:
136+
137+
```text
138+
formDataPost : {"formData": ["field1-name1", "field2-name1", "field3-name1"], "templateFields":['field1-name','field2-name','field3-name']]}
139+
```
140+
141+
-`"formData"` is the multi-dimensional array of form field values : [['a','b'],['c','b']] received from the server and encoded
142+
143+
-`"templateFields"` are the input fields in the template with index suffixed after the field name. For example, `field1-name{index}`, `field2-name{index}`, `field3-name{index}`
144+
57145
## Options
58146

59147
The PopupWindow widget has the following options:

0 commit comments

Comments
 (0)