List of field names (rather than combo box)

Hi,

I’m building a sort editor. Two boxes, the one on the left displaying the list of fields for the table of interest, and the one on the right containing the fields that the user has selected for the sorting operation.

I know how to get the list of fields from the table I want,

var aFieldNames = jsTable.getColumnNames();

To display the fields array on the form, do I need some sort of dummy table? A “virtual” form and virtual data source, using the solution model? Calculated fields that are attached to an existing table? I’ve looked at a variety of forum posts, but I haven’t been able to weave them together into an approach.

In 4D, this was very easy, because forms can display scrolling arrays. In Servoy, I can show the arrays in a combo box, just not in a scrolling box. Can anyone provide guidance?

Thank you,
Don

Hi Don,

In my opinion, the way to do this is to create a dataset, from this dataset you can create a datasource (a different object) which can be bound to a form using the solutionModel.

This way you can:

  • create a form in the same style as the other forms
  • create support for drag & drop
  • have a smart- + webclient compatible solution

Hope this helps

in the next version of servoy we have support for a ListBox type.
But until then i think a form in a tableview is the best option

Johan,

Can You give some more information on the listBox type.
What it is, when to use combobox and when to use listBox, …

Thanks,

its just a listbox like described above
so a list (of a specific size, showing X rows at once with a scrollbar) that has its values from a valuelist and can be in single or multi select.

Hi Marc,

I used the following code to attach the virtual data source to the existing form,

var v_ds = databaseManager.convertToDataSet(aFieldNamesFiltered);
var v_dataSource = v_ds.createDataSource(‘ds_field_names’,[JSColumn.TEXT]);
var v_form = solutionModel.getForm(‘order_by_fields’);
v_form.dataSource = v_dataSource;
var v_field_1 = v_form.getField(‘field1’);
v_field_1.dataProviderID = “field1”;
controller.recreateUI();

When I call the form, it appears that Servoy has found the dataset (by the number of paginations), but the individual items aren’t displayed (attached pic). It also displays a second column (which at present shouldn’t exist).

I hope you don’t think I’m being too blockheaded about this. Any advice?

Thank you,
Don

Hi Don,

I just made a checkboxlist dialog, that probaly does what you want.
The dialog is fully generated using solutionModel, so I guess you can do the same thing :wink:

In order to display a checkbox column in the dialog, you need to create a custom datasource, (just by what you allready did).
But this time you need to include a non-existing dataprovider in your query. For example: SELECT 0 as checkbox, contact_name FROM contact.
Use the first column from the query as checkbox dataprovider in your custom datasource.
Apply the datasource to a tableview form and voila, you have something that could look like this : :)

[attachment=0]Multivalues dialog.png[/attachment]
Hope this helps!

Hi Karel,

I created a dataset from three arrays, only one of which I wanted to display, and then used the following code to display it,

// show the vldtn_ds dataset in the validation window, on the student form –
var vldtn_dataSource = vldtn_ds.createDataSource(‘field_name_source’, [JSColumn.TEXT, JSColumn.TEXT, JSColumn.TEXT]);
var vldtn_form = solutionModel.getForm(‘student_i_diagnostics’);
vldtn_form.dataSource = vldtn_dataSource;
var fs = databaseManager.getFoundSet(vldtn_dataSource);
var vldtn_field_1 = vldtn_form.getField(‘field1’);
vldtn_field_1.dataProviderID = “vDesc”;
controller.recreateUI();
application.updateUI();

I’ve attached a picture of the resulting list, which is in the lower left corner of a larger form for data entry.

I had a little bit of trouble getting it to display properly, as you can see from the earlier post. If you have any suggestions regarding the code, please let me know.

Thanks,
Don

Hi again,

I forgot to ask…

In my original example (selecting fields to sort), I had wanted to drag across to another (initially empty) box. Is there a way to do that with this approach? It would be similar to what Servoy Developer does when selecting the parts of a form (“Available” and “On current form”).

Thanks,
Don

Hi Don,

I’m not sure why you’re setting a var as dataprovider, but this is the way I made the checkboxlist:

//1. Create an empty dataset
globals.gFormDS = databaseManager.createEmptyDataSet(0, ['checkbox', 'return_value', 'display_value']);

//2. Loop through your array (or dataset from a query)
var vCheckboxValue = 0, vReturnValue, vDisplayValue;
for(var x in myArray){
         vCheckboxValue = myArray[x][0];
         vReturnValue = myArray[x][1];
         vDisplayValue = myArray[x][2];
        globals.gFormDS.addRow(x+1, [vCheckBox, vReturnValue, vDisplayValue]);
}

//3. Create the datasource
var vFormDatasource = globals.gFormDS.createDataSource('multivalueset', [DM_COLUMNTYPE.INTEGER, DM_COLUMNTYPE.INTEGER, DM_COLUMNTYPE.TEXT]);

//4. Create tableview form
var jTableForm = solutionModel.newForm(vDialogTableForm, vFormDatasource, null, false, 330, 200);
jTableForm.view = JSForm.LOCKED_TABLE_VIEW;
jTableForm.scrollbars = SM_SCROLLBAR.HORIZONTAL_SCROLLBAR_NEVER | SM_SCROLLBAR.VERTICAL_SCROLLBAR_AS_NEEDED;

//5. Add checkbox field on form
var jField = jTableForm.newField('checkbox', JSField.CHECKS, 3, 0, 25, 25);
jField.name = 'fld_checkbox'

//6. Add displayValue field
jField = jTableForm.newField('display_value', JSField.TEXT_FIELD, 25, 0, 200, 25);
jField.name = 'fld_display_value'
jField.editable = false;
jField.anchors = SM_ANCHOR.NORTH | SM_ANCHOR.WEST | SM_ANCHOR.EAST;

Then the last part is that you need to decide how you’re going to handle the data changes (when a user selects or deselect a checkbox).
I did that with a Save button on my dialogform, but you also could make an onDataChange method on the checkbox field. Whatever you like.

The reason why I use a global to store the dataset is that you can allways read the -modified- dataset from it, wherever you are in your solution, but maybe this is not nessecary for you.
I hope you are able to create a proper checkboxlist with this example.

I had wanted to drag across to another (initially empty) box

You can find a Drag&Drop sample solution here: http://wiki.servoy.com/display/samples/Sample+solutions. The sample solution will help you understand Drag&Drop functionality in Servoy.

Hi Karel,

I designed the form in the GUI, so I’m “filling” the variable on the form with the diagnostic information from the dataset. In this case, I’m not allowing user enterability – the only thing the user can do is click on a row, in which case the input form moves to the appropriate tab and field associated with the error message.

In the case of the sort editor, the best thing would be for the users to be able to double-click on a row, or drag a row, so that the item is created in the right-hand list. So I don’t think I need enterability, like with a check box.

I’m a newbie, and my understanding of multi-dimensional javascript arrays is nil. So I need to look more carefully at how you are doing the dataset construction. (In my case I’m building them based on either a selection of record validation items or a list of fields in a table.)

Thanks so much for taking the time to reply, and also for the drag-drop link.

Don