svyLookup format field value boolean

Forum to discuss the new web client version of Servoy.

svyLookup format field value boolean

Postby pitc » Sun Jul 18, 2021 9:03 pm

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)
Code: Select all
   
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:
Code: Select all
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!
Tom
prospect-saas.com
pitc
 
Posts: 115
Joined: Thu Nov 14, 2019 2:22 pm
Location: Ottawa, Ontario, Canada

Re: svyLookup format field value boolean

Postby paronne » Mon Jul 26, 2021 12:46 pm

Hi Tom,

i may suggest to look into the stand-alone PopupFilter for booleans

https://github.com/Servoy/svyPopupFilte ... kers#check

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:

Code: Select all
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];
}


Regards,
Paolo
paronne
 
Posts: 202
Joined: Fri Nov 02, 2012 3:21 pm

Re: svyLookup format field value boolean

Postby pitc » Mon Jul 26, 2021 6:24 pm

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:
Code: Select all
    //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:
Code: Select all
   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:
Code: Select all
[Undefined,Undefined]


Not sure there is a defect in the way I am doing this (the wiki is insufficient to explain).
Tom
prospect-saas.com
pitc
 
Posts: 115
Joined: Thu Nov 14, 2019 2:22 pm
Location: Ottawa, Ontario, Canada

Re: svyLookup format field value boolean

Postby pitc » Mon Jul 26, 2021 8:04 pm

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....?
You do not have the required permissions to view the files attached to this post.
Tom
prospect-saas.com
pitc
 
Posts: 115
Joined: Thu Nov 14, 2019 2:22 pm
Location: Ottawa, Ontario, Canada

Re: svyLookup format field value boolean

Postby pitc » Mon Jul 26, 2021 8:29 pm

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.
Tom
prospect-saas.com
pitc
 
Posts: 115
Joined: Thu Nov 14, 2019 2:22 pm
Location: Ottawa, Ontario, Canada

Re: svyLookup format field value boolean

Postby pitc » Mon Jul 26, 2021 8:38 pm

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:
https://support.servoy.com/browse/SVYX-277
Tom
prospect-saas.com
pitc
 
Posts: 115
Joined: Thu Nov 14, 2019 2:22 pm
Location: Ottawa, Ontario, Canada

Re: svyLookup format field value boolean

Postby paronne » Wed Jul 28, 2021 9:49 am

Hi Tom,

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:

Code: Select all
   var lookupObj = scopes.svyLookup.createLookup(datasources.db.example_data.products.getDataSource());
   lookupObj.setMultiSelect(true);
   //lookupObj.setLookupForm(forms.multiLookup);
   
   // add fields
   lookupObj.addField('productname').setTitleText('Product');
   lookupObj.addField('products_to_suppliers.companyname').setTitleText('Supplier');
   lookupObj.addField("isDiscontinued")
      .setTitleText('Discontinued')
      .setSearchable(false);
   lookupObj.addField('unitprice')
      .setSearchable(false)
      .setTitleText('Price')
      .setFormat('#,###.00')
         
   // show pop-up
   lookupObj.showPopUp(onSelect, elements.btnNewProduct, controller.getFormWidth()/2, 412);


Code: Select all
function isDiscontinued()
{
   if (discontinued) {
      return "Yes"
   } else {
      return "No"
   }
}


Note, you should make sure calculated fields added in lookup are not searchable, otherwise will give an error upon search.

Will look into https://support.servoy.com/browse/SVYX-277 for the upcoming release.

Regards,
Paolo
paronne
 
Posts: 202
Joined: Fri Nov 02, 2012 3:21 pm

Re: svyLookup format field value boolean

Postby pitc » Wed Jul 28, 2021 2:33 pm

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.
Tom
prospect-saas.com
pitc
 
Posts: 115
Joined: Thu Nov 14, 2019 2:22 pm
Location: Ottawa, Ontario, Canada

Re: svyLookup format field value boolean

Postby paronne » Wed Jul 28, 2021 3:09 pm

Hi Tom,

happy to enhance the wiki; I have just included an example using a calculation :wink: .
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.

Code: Select all
       // 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);


Regards,
Paolo
paronne
 
Posts: 202
Joined: Fri Nov 02, 2012 3:21 pm

Re: svyLookup format field value boolean

Postby pitc » Wed Jul 28, 2021 5:06 pm

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?
Tom
prospect-saas.com
pitc
 
Posts: 115
Joined: Thu Nov 14, 2019 2:22 pm
Location: Ottawa, Ontario, Canada

Re: svyLookup format field value boolean

Postby pitc » Wed Jul 28, 2021 5:39 pm

I did try the valuelist approach and it does work!
Thanks.
Tom
prospect-saas.com
pitc
 
Posts: 115
Joined: Thu Nov 14, 2019 2:22 pm
Location: Ottawa, Ontario, Canada


Return to Servoy NGClient

Who is online

Users browsing this forum: No registered users and 5 guests