PDA

View Full Version : FormView Data API Changes to the settings object


ABC123

Beta Spark
02-05-2016, 05:58 PM
Recent changes to the FormView Control's API have been made to simplify passing data to Editors. FormView settings are now encapsulated inside the settings.formView namespace. This helps to reduce conflicts between user-defined settings and system settings. This change affects the settings['*a5column'] and settings.data objects.

Using settings.formView.active.path

Before, when getting the name of the field being updated to set a title, you could use settings['*a5column'] to fetch the field's name:


var title = settings['*a5column'];
var eleTitle = $('EDITOR_2.FIELDLABEL');
eleTitle.innerHTML = title;


With the recent API change, you should use settings.formView.active.path instead:


var title = settings.formView.active.path;
var eleTitle = $('EDITOR_2.FIELDLABEL');
eleTitle.innerHTML = title;


Using settings.formView.active.target

Supported in Alpha Anywhere builds released on or after 12/21/2016:

For Group Editors, settings['*a5column'] was previously used to determine what field was selected so focus could be set to a specify control in the Group Editor. Unfortunately, you cannot use settings.formView.active.path to determine the selected field. settings.formView.active.path will be an array containing all of the fields that are assigned the Group Editor for editing.

To get the field that was clicked when the Group Editor was activated, use settings.formView.active.target. For example:



var control = settings.formView.active.target;
control = 'EDITOR_3_' + control;
var ele = {dialog.object}.getPointer(control);
ele.select();


Using settings.formView.data

In the "Cascading Dropdownbox Editors" video demonstration (http://www.alphasoftware.com/video-library/?v=4926), the settings.data object is used to determine what value to filter the City dropdown box by looking up the value of the State field. This is the code from the "Set value in editor":


if(settings['fieldName'] == 'State') {
var choices = getStates();
} else if(settings['fieldName'] == 'City') {
var state = settings.data.State;
choices = getCities(state);
}

if(typeof choices != 'undefined') {
{dialog.object}.populateDropdownBox('EDITOR_2_TXTBOX',choices,true);
}


{dialog.object}.setValue('EDITOR_2_TXTBOX',value);


With the new changes, this block of code becomes the following:


if(settings['fieldName'] == 'State') {
var choices = getStates();
} else if(settings['fieldName'] == 'City') {
var state = settings.formView.data.State;
choices = getCities(state);
}

if(typeof choices != 'undefined') {
{dialog.object}.populateDropdownBox('EDITOR_2_TXTBOX',choices,true);
}


{dialog.object}.setValue('EDITOR_2_TXTBOX',value);


Existing UX components that use the FormView control are unaffected, however when building new Editors, you should use the new syntax.

This change to the FormView settings object was originally posted in the Pre-Release Notes (http://downloads.alphasoftware.com/A5V12Download/ReleaseNotes/prereleasenotes.html).

Additional Resources

To learn more about the FormView control and Editors and Editor Sets, checkout the resources listed below:

The Basics

Introduction to the FormView Control (http://www.alphasoftware.com/alphaforum/showthread.php?115121-Introduction-to-the-FormView-Control): A discussion about the FormView, Editors, and Editor Sets.

Creating Editors

Editors: Using a Dropdown Box (http://www.alphasoftware.com/alphaforum/showthread.php?115754-Editors-Using-a-Dropdown-Box): A discussion about how to use a dropdown box as an editor
Editors: Cascading Dropdown Boxes (http://www.alphasoftware.com/alphaforum/showthread.php?115802-Editors-Cascading-Dropdown-Boxes): A continuation of a previous thread, Editors: Using a Dropdown Box, which covers how to implement cascading dropdown boxes within the context of tablet form Editors and Editor Sets.
Editors: Pre-Defined List Control Editor (http://www.alphasoftware.com/alphaforum/showthread.php?116194-Editors-Pre-Defined-List-Control-Editor): Dropping in a list control for editing data is made easier with the Editor-List. Learn how to leverage this control in your mobile apps.
Editors: Populating a List from a SQL Query (http://www.alphasoftware.com/alphaforum/showthread.php?116123-Editors-Populating-a-List-from-a-SQL-Query): Lists can be populated from a variety of sources. Discover how the onDialogInitialize event can be used to cache data to populate a List control Editor.
Editors: Cascading List Control (http://www.alphasoftware.com/alphaforum/showthread.php?116068-Editors-Cascading-List-Control): Learn how to create a cascading List control Editor.
Introduction to Group Editors (http://www.alphasoftware.com/alphaforum/showthread.php?115894-Introduction-to-Group-Editors): Learn how to edit a group of controls together using a Group Editor.
Setting the Editor & Editor Set at Run-Time (http://www.alphasoftware.com/alphaforum/showthread.php?116528-Setting-the-Editor-amp-Editor-Set-at-Run-Time&highlight=formview): Learn how to choose the Editor and Editor set to use at run-time using javascript.

Other Types of Editors

Switch Editors (http://www.alphasoftware.com/alphaforum/showthread.php?115700-Switch-Editors): Discover how you can use an in-line switch to edit values instead of an editor set for binary and multi-value fields.
FormView Image Capture (http://www.alphasoftware.com/alphaforum/showthread.php?116089-FormView-Image-Capture): Learn how easy it is to capture images using the FormView control

brainwater
12-19-2016, 11:27 AM
When the editor is using fields in a group
settings.formView.active.path returns a string of all the fields in the group
settings["*a5column"]; returns undefined

how can I get the name of the field that was clicked on the form to open the editor ?

Davidk
12-20-2016, 02:10 AM
Bruce, I'm sure there's a better way to do this... but... this isnt' too bad. It's a bit of a workaround. I can't see anything in the settings object that specifies the control you clicked on to display the group editor.

However... get into the FormView. For each Field in the Group... fill in the Property "Field title in editor" with the exact name of the field. E.g. If you have a field name Qty... enter Qty... or QTY as a Field Title.

Because we're in a group, the Textbox for Qty in the Group... let's say EDITOR_3_QTY... can have a Field Label... e.g. Quantity... so we're not message anything up.

Now... in the Editor, Show Editor event... you can do this...

var control = settings.title;
control = 'EDITOR_3_' + control;
var ele = {dialog.object}.getPointer(control);
ele.select();

settings.title holds the title of the field you clicked on... and now the balance of the code can continue.

brainwater
12-20-2016, 08:52 AM
Thanks, after a lot of looking I came up with the same solution last night, it actually works pretty well because I can also use the title on the editor also
sometimes the simplest solution is the best
thanks for the response

Beta Spark
12-20-2016, 11:33 AM
When the editor is using fields in a group
settings.formView.active.path returns a string of all the fields in the group
settings["*a5column"]; returns undefined

how can I get the name of the field that was clicked on the form to open the editor ?

Hello Bruce,

This is an excellent question. If the editor set is a Group editor, the settings.formView.active.path is an array. I can't find anything in the formView object that indicates what field was selected.

I have passed this on to the dev team and they're looking into it.

Thanks!

Beta Spark
12-20-2016, 12:42 PM
Hello Bruce,

In tomorrow's pre-release build (and future releases), you can get the selected field for a group editor as follows:


var control = settings.formView.active.target;
control = 'EDITOR_3_' + control;
var ele = {dialog.object}.getPointer(control);
ele.select();

Davidk
12-21-2016, 12:47 PM
Excellent... thanks.