Changing a Virtual Field's value from code

30 views
Skip to first unread message

Chris

unread,
Aug 14, 2017, 1:40:07 PM8/14/17
to ParaSQL Support
Is it possible to change the value of a virtual field from a block of code? I'm trying to clear (or set) the value of a virtual character field from a button's event handler.

The following attempt results in an error about "a.getString is not a function" when the event tries to fire:

parasql.app.getWidgetById('ID1820').setDataValue('Hello');

I also tried

parasql.app.getWidgetById('ID1820').value = 'Hello';

and while this doesn't throw an error, it doesn't update the field on the screen.
Message has been deleted

Robert

unread,
Aug 14, 2017, 2:39:51 PM8/14/17
to ParaSQL Support
If you have a Virtual Character Field you can set and display its value as follows:

var myCharacterField = parasql.app.getWidgetById('ID1820');
myCharacterField
.getDataValue().setString('Hello'); // sets the value only - does NOT automatically display
myCharacterField
.displayDataValue(); // causes the value to display


The getDataValue() method returns a DataValue object that you can then call the setter and getter methods on. 

Chris

unread,
Aug 15, 2017, 8:14:55 AM8/15/17
to ParaSQL Support
Thanks, Robert. That worked well.

Out of curiosity, is there any advantage to using the setDataValue(newValue) method in some cases if you need to fire the virtual field's event handlers? After looking at the API again today I finally got the following example to work:

var myDataValue = new parasql.schema.DataValue();
myDataValue.setString('Hello');

parasql
.app.getWidgetById('ID1820').setDataValue(myDataValue);

Robert

unread,
Aug 15, 2017, 2:26:03 PM8/15/17
to ParaSQL Support
Per the docs on the setDataValue() method:

"Setting a field's value with this method makes it behave as if it were set by the user (with the exception of validation). The value is copied from the specified newValue, the value is rendered in the UI including any formatting, any dependent fields are recalculated, any Data Links are performed, and finally a "change" event is fired to all listeners."

So it does a lot more, but you are restricted to working only with the currently active value. If you imagine a list of 50 records, there is only 1 field but 50 DataValue objects for that field (one for each record). If the user is on a particular record (already clicked in it) and you are modifying a single value, this method would work too. However, if you needed to modify (for example) 20 records you would be better off searching throw the rows and modifying the DataValue objects you wanted, then calling a single myRecordObject.redisplay() to re-render everything correctly (including dependent field calculations  and a lot more).

In your case of a Virtual Field outside of a record, either would work as there is a 1:1 correspondence  between the Field object and the DataValue object.


Chris

unread,
Aug 29, 2017, 3:16:52 PM8/29/17
to ParaSQL Support
Good to know that about the Record Objects. Thanks for taking the time to explain.
Reply all
Reply to author
Forward
0 new messages