Editing Data in a ViewBox
Description
You can connect a textbox editor to a ViewBox control so that you can update the data in the ViewBox.
Add a TextBox Control to Edit ViewBox data.
In the UX Builder's UX Controls page open the 'Containers' menu. Click the [Container] option.
From the Container Type list select the 'EditorSet' option and 'OK' to add an EditorSet to the component.
Highlight the EditorSet. In the 'Containers' menu click on the [Container] option a second time.
Select the 'Editor' option and click 'Insert After' to add it to the EditorSet.
Highlight the Editor. In the Editor container's properties list on the right click the button next to the 'Set value in editor' property. This should be in the Editor Properties section.
Add the following javascript to the 'Set value in editor' dialog and click OK.
{dialog.object}.setValue('editor_1_edit',value);
Click the button next to the 'Get value from editor' property, this is also in the Editor Properties section.
In the 'Commit Editor' add the following code:
return {dialog.object}.getValue('editor_1_edit');
Highlight the Editor. Open the 'Data Controls' menu and click on the [TextBox] option. Give the textbox the name 'editor_1_edit'.
Highlight the TextBox control. Open the 'Other Controls' menu and click on the [Button] option to add a button control underneath the textbox.
In the properties list on the right change the 'Button text' property to read 'Done'. This property is in the Button Properties section.
Scroll down the properties list to the 'Javascript - (Touch, Mouse, Pointer Events) section. Click the button next to the 'click' property.
In the 'Edit Click Event' dialog select 'Text mode', add the following code, and click 'Save':
{dialog.object}.editorCommit('EDITORSET_1')
Highlight the 'Done' button in the tree. In the Other Controls menu click on the [Button] option a second time to add another button to the component.
In the properties list set the 'Button text' property for this button to read 'Cancel'.
In the 'Javascript - (Touch, Mouse, Pointer Events) section click the button next to the 'click' property
In the 'Edit Click Event' dialog again select 'Text mode'. Add the following code and click 'Save'.
{dialog.object}.editorCancel('EDITORSET_1');
Highlight [EditorSet End: EDITORSET_1]. Open the 'Data Controls' menu and click on the [ViewBox] option to add a ViewBox control below the EditorSet. Give the ViewBox the name 'form'.
Highlight the ViewBox control. In the properties list click the button next to the 'ViewBox properties' property in the ViewBox Properties section. The ViewBox Builder will open.
In the Data Source pane click the button next to the 'ViewBox type' property and change its setting to 'Data'.
In the ViewBox Data section click the dropdown next to the 'Datasource type' property and select 'Static JSON'.
Add the following JSON data and click OK.
{ firstname: 'Selwyn', lastname: 'Rabins', title: 'President' }
Open the ViewBox Layout pane and select the 'Freeform editor' option.
Add the following HTML to the template.
<div a5-item="edit" a5-value="firstname" class="item"> <div class="title">First name</div> {firstname} </div> <div a5-item="edit" a5-value="lastname" class="item"> <div class="title">Last name</div> {lastname} </div> <div a5-item="edit" a5-value="title" class="item"> <div class="title">Title</div> {title} </div>
Open the CSS pane and add the following CSS classes.
.item { padding: 4px; cursor: default; } .itemSelected { background: #bbd0ff; } .title { font-size: 75%; color: #999; }
Open the Items pane and click the 'Add item' button. Give the item the name 'edit'
In the properties list on the right check the 'Selectable' property in the Item Properties section.
Set the 'Selected class name' property in the same section to be the 'itemSelected' class that you defined.
Click the button next to the 'onSelect' property in the Javascript section of the item properties list.
Add the following Javascript and click OK.
var val = this.data[v]; {dialog.object}.editorFromValue('EDITORSET_1','EDITOR_1',val,{ field: v },function(value,settings){ var fObj = {dialog.object}.getControl('form'); fObj.data[settings.field] = value; fObj.refresh(true); });
Close the ViewBox Builder and run the component in Live Preview.
Highlight one of the fields and change the name of the field in the Textbox editor
Click the 'Done' button and you should see the JSON data in the field change.