
Originally Posted by
dougeven
Hi,
Since my question(s) got buried a bit in my previous post, here they are more clearly:
1. The "settings.data" object contains the values for the fields in the formview. If I need to access the data values for the parent row in a parent list control for which the current formview is a child, can I do it from the "Set value in editor" property of an Editor?
2. How can I acquire and pass the data value into an Editor by calling a javascript function in the Editor Settings property of a formview field? Any examples?
Thanks.
Hi Doug,
You can reference the parent list using {dialog.object}.getValue to access data values in the parent row of the list control the formview is based on. For example:
Code:
var id = {dialog.object}.getValue('list::list1::RECORD_ID');
If the list which is used as the data source for your FormView also has a parent list control, you can reference data in the current row in that parent list control the same way:
Code:
var parent_id = {dialog.object}.getValue('list::list1Parent::PARENTRECORD_ID');
Both code examples above are javascript and can be used anywhere in your UX component that you can write javascript code. This includes "Set value in editor", "Show editor", "Hide editor", "Get value from editor", and "Validate editor". You can use them in javascript functions that are called from client-side templates, client-side show/hide expressions, functions called when setting the value for your Setting in User Defined Editor and Template settings in the FormView, etc.
RE: Calling a Function for Editor Settings
You have two options for calling javascript functions to define the Value for a setting. The easiest is to create a javascript function, defined in the Javascript Code section for the UX component, and call it using the Javascript: prefix. EG:
Code:
Javascript:generateMaxDate
The javascript function can be defined in the Javascript Code section or in a javascript file loaded when the component is first launched.
Alternatively, you can write the javascript directly as an anonymous function in the value box. An anonymous function can be used to create a setting that is a function or can be used to calculate the value of a setting.
Setting as an Anonymous Function
Assuming you created a setting called "maxDate" and defined it as an anonymous function as follows:
Code:
function:function(){
var d = new Date();
return d.getDate()+"-"+(d.getMonth()+1)+"-"+d.getFullYear();
}
This creates a setting called "maxDate" that is a function. You can reference it in the settings object like it was a method of settings. EG:
Code:
var maxDate = settings.maxDate();
alert(maxDate);
Setting Calculated using an Anonymouns Function
You can execute the Anonymous function immediately by adding parentheses to the definition of the function in the Value property for the maxDate setting. This is effectively identical to defining a function in an external file or the Javascript Code section and using the "Javscript:myfunctionname" as the value definition:
Code:
function:function(){
var d = new Date();
return d.getDate()+"-"+(d.getMonth()+1)+"-"+d.getFullYear();
}()
Referencing maxDate in the settings object doesn't require calling it as a function. You can treat is as a statically defined object.
Code:
var maxDate = settings.maxDate;
alert(maxDate);
Anonymous Function word of Caution
I would like to point out that should you choose to put comments in your annonymous function definition, you should use the /* */ comment delimeters. Using the // comment style may cause unexpected problems.
I hope this was helpful. Let me know if you have any additional questions!
Bookmarks