I am using svyLookup.
One of the fields for the look up is an integer (0 or 1 only) representing boolean Yes/No.
I am trying to use the following code to format the field as either text ‘Yes’ or ‘No’ or as an image of a tick mark or a ‘not’ tick mark (e.g x)
lookupField = vf_menuLookupObj.getField(2);//should be is_cater
lookupField.setTitleText('Is Cater');
lookupField.setFormat(format);
where format is a string value.
However I am not sure how to have a conditional format like:
var format = value == 1 ? 'Yes':'No'
where value is the column value of 1 or 0
The svyLookup wiki and docs curiously omit such an example.
Maybe a setStyle?
Suggestions appreciated!
Has been introduced since version v1.2.0 of the svyPopupFilter module.
Stand-alone mode it means: doesn’t require a grid to be filter, the popups of such modules can be used as stand-alone pickers just as the svyLookup module.
An example of it is available in the default Servoy Sample Application
The date picker is used to pick an shippeddate and a requireddate of an order:
function onActionPickRequiredShippedDates(event) {
// create the popup filter
var datePicker = scopes.svyPopupFilter.createDateFilter();
// set popup template form
datePicker.setRendererForm(forms.customDatePopupFilter);
// set selected values
datePicker.setValues([foundset.shippeddate, foundset.requireddate]);
// show the picker
datePicker.showPopUp(onRequiredShippedDatesPicked, elements.shippeddate);
}
function onRequiredShippedDatesPicked(values, operator, dataPicker) {
foundset.shippeddate = values[0];
foundset.requireddate = values[1];
}
Paolo,
thanks for the suggestion.
Unfortunately it does not work for me.
My original question was how to format the boolean - seems to be a defect to me.
Your suggestion to use svyPopupFilter still shows the boolean as 0/1 - presumably because still using the svyLookUp object for the svyPopupFilter.
Using svyPopupFilter version 2.0.2
Also this defect:
The returned values when I select two selections (multi-select mode == true) is partially correct:
There is an Array of two values - but both entries are “undefined”.
What I do is to create the lookup object, then I create the select object:
//create a lookup object with the filtered foundset
vf_menuLookupObj = scopes.svyLookup.createQueryLookup(q,'menuLookUp',true);
// Set the lookup dataprovider
vf_menuLookupObj.setLookupDataProvider('menu_num'); //essentially becomes the pks for use in a query
vf_menuPopupFilter = scopes.svyPopupFilter.createSelectFilter('menu_num', vf_menuLookupObj);
var popUpComponentTarget = elements.button_menu_lookup;
//using svyPopupfilter
vf_menuPopupFilter.showPopUp(onSelectMenuPopup,popUpComponentTarget,600, 200);
return;
the onSelectMenuPopup is:
if (values && values.length){
application.output('onSelectMenuLookup #values= ' + values.length,LOGGINGLEVEL.DEBUG);
//save the values as the pks to select in a query
vf_menus_values_selected = values;
vf_menus_values_selected_previous = values;
}//values not null
else {
vf_menus_values_selected = null;//wipe out previous values if any
}
return;
in the debugger we see the values array as:
[Undefined,Undefined]
Not sure there is a defect in the way I am doing this (the wiki is insufficient to explain).
Debug Information:
I set the debugger to stop on the
SvySelectFilter.prototype.showPopUp
method.
I then examined the variables when the popup closes and the
svySelectCallback
function is called.
The records array from the lookup object are indeed correct, but the values array is incorrect.
See the attached screen captures.
So maybe the svyLookup is at fault…?
I think I found my problem cause:
When setting the dataprovider name (as a string) in the svyLookup object I used ‘menu_num’.
This is the table column name.
However the query used to fetch the records from the table for the lookup/filter has the alias: ‘menu_number’.
After changing to use ‘menu_number’ the values array returns the correct values.
It is not clear to me that to specify the dataprovider name one should use the query dataprovider name and not the original table column name.
Of course the original issue is that the boolean format does not work remains.
Not quite related but when restoring the previous values to the SearchFilter these values are not checked/highlighted.
I have raised this as an issue in Jira:
I have missunderstod your use case initially, that’s why i suggested the svyPopuFilter for check fields. Though you were looking for a boolean selection (where user can select as value either Yes or No).
the svyLookup is using a Servoy Grid to display the fields; therefore you can use same patterns normally used to display data in grid to configure the fields.
If you want to show a yes/no for a single field in grid you can for instance use a calculation, as in the example below:
Paolo,
I did not know that one could provide a function that does the calculation.
I was examining the code for the inmem foundset of the svyLookup class but did not see a way to do it.
Thanks for showing me. I will try it.
Perhaps the wiki could be enhanced with this snippet.
happy to enhance the wiki; I have just included an example using a calculation .
While updating the wiki I noticed there is already an example of a similar use case. Show discontinued products (having DB value 0, -1) with text ‘Available’ or ‘Discontinued’.
In the wiki example a custom valuelist is used instead of a calculation; just another valid pattern to solve the same problem.
// create lookup object
var lookupObj = scopes.svyLookup.createLookup(datasources.db.example_data.products.getDataSource());
// add fields
// related data is supported
lookupObj.addField('products_to_categories.categoryname').setTitleText('Category');
lookupObj.addField('productname').setTitleText('Product');
lookupObj.addField('products_to_suppliers.companyname').setTitleText('Supplier');
// Valuelists and non-searchable fields supported
lookupObj.addField('discontinued')
.setTitleText('Available')
.setSearchable(false)
.setValueListName('product_availability');
// calculation, non-searchable fields example (if (discontinued) return 'Discontinued' else return 'Available')
// lookupObj.addField('isDiscontinued')
// .setTitleText('Available')
// .setSearchable(false)
// formatted, non-searchable field example
lookupObj.addField('unitprice')
.setSearchable(false)
.setTitleText('Price')
.setFormat('#,###.00')
// show pop-up
var component = elements.productID;
var initialValue = application.getValueListDisplayValue(elements.productID.getValueListName(),selectedProductID);
lookupObj.showPopUp(onSelect,component,null,null,initialValue);
I have tried your suggestion and it does not work.
Perhaps it is because the lookup object is created from a query and the fields are automatically created?
How to add a calculation to the internal inmem table?