Solution Model Unable to Set OnAction

Hi All,

I am building a form via the solution model. Its a record view form.
Based on some data in a table (db) I need to populate a set of fields.
I have done the following,

var sSQL = "SELECT A, B FROM testTable";
	
	var dsDataset = databaseManager.getDataSetByQuery('dbTest',sSQL,null,-1);
	
	var dsdataSource = dsDataset.createDataSource('navigationDS',[JSColumn.TEXT, JSColumn.TEXT]);
	
	var sForm = 'frm_test_form';
	history.removeForm(sForm ); 
	solutionModel.removeForm(sForm );	
		
	var jsform 			= solutionModel.newForm(sForm , dsdataSource, null, true, 510, 300);
	jsform.view 		= JSForm.RECORD_VIEW;	
	jsform.styleName 	= 'testStyle';		
	jsform.scrollbars   = SM_SCROLLBAR.HORIZONTAL_SCROLLBAR_NEVER;
	jsform.navigator	= SM_DEFAULTS.NONE;

I wanted to create a set of labels with the label to display the contents of column A. However this does not seem to work

aLabels[index] = jsform.newLabel('A', (2 + (index * 120)), 10, 110, 20);

So instead I switched to using text fields,

var aFields 	= new Array();	
	for (var index = 1; index <= dsDataset.getMaxRowIndex(); index++) {
		var row = dsDataset.getRowAsArray(index);		
			
		aFields[index] 			= jsform.newField(row[0] , JSField.TEXT_FIELD, (2 + (index * 120)), 10, 110, 20);
		aFields[index].editable 	= false;
		aFields[index].name		= row[0];
		aFields[index].styleClass 	= 'button';	
		aFields[index].borderType 	= 'EmptyBorder, 0, 0, 0, 0';
								
	}

I have two issues

  1. When I use ```
    jsform.newField(‘A’] , JSField.TEXT_FIELD, (2 + (index * 120)), 10, 110, 20);
The values get set. But as expected, I get the same value for all the fields. When I use the array,

jsform.newField(row[0] , JSField.TEXT_FIELD, (2 + (index * 120)), 10, 110, 20);

I don't get any data. The array has data, but its not setting to the text field.

2) How can I set an onAction (which call a function) event to the text fields?

Hi Hareendra,

  1. Can you check what is really in row[0] and what datatype it is? Also check if this name exists as a dataprovider (since you are setting it as one).

  2. To add an existing form method to a form elements you use the following syntax:

aFields[index].onAction = jsForm.getMethod('methodName');

To use an existing global method you use the following syntax:

aFields[index].onAction = solutionModel.getGlobalMethod('scopeName','methodName');

Or if you want to create a new method using the solutionModel you use the following syntax:

var jsMethod = jsForm.newMethod('function myMethod() {// your code here \n}'); // create this only once and reuse this object

aFields[index].onAction = jsMethod;

Hope this helps.

Hi Robert,

Thank you for the input.
the row[0] is as follows,

var row = dsDataset.getRowAsArray(index); 

The dataset is populated via a query. The value (column) type is a string

On the onAction(), is there a way to pass a parameter?

Regards,
Hareendra

Hi Hareendra,

hareendra:

var row = dsDataset.getRowAsArray(index); 

The dataset is populated via a query. The value (column) type is a string

And does this value truly match up with your dataprovider?

hareendra:
On the onAction(), is there a way to pass a parameter?

Other than the default JSEvent ? I don’t think you can add any literal parameters to the onAction event like you can in designtime.
You might want to file that as a feature request.

hareendra:
On the onAction(), is there a way to pass a parameter?

You can use SolutionModel.wrapMethodWithArguments() for this.
this function takes a JSMethod and your arguments and returns the wrapped method as JSMethod again which you can use to bind to the onAction.

mboegem:
You can use SolutionModel.wrapMethodWithArguments() for this.

I stand corrected :)
You can indeed.