javascript and filters

256 views
Skip to first unread message

jimbo

unread,
Jan 24, 2020, 7:00:05 PM1/24/20
to Jam.py Users Mailing List
I"m using an on_field_select_value to filter a lookup form.

The item has a filter defined with Filter Type  "CONTAINS".

function on_field_select_value(field, lookup_item) {
if ( field.field_name === 'myfield'){
lookup_item.filters.myitem.value = 'my words';
}

Obviously that isn't working because  lookup_item.filters.myitem.value expects an id of the item in the filter. When I issue an ID of and item in the database, i get fitlered records. But my FilterType is CONTAINS. I should be able to set the filter to a text value and have the CONTAINS filter use it. But not sure how.

So my question is, how can set the value of a filter by text where I've a CONTAINS filter type on the item?

rrad

unread,
Jan 26, 2020, 10:46:47 AM1/26/20
to Jam.py Users Mailing List
Hi,
I don't think you are on the right track.
Use set_where () to set the filter condition.
How conditions are set:

jimbo

unread,
Jan 26, 2020, 1:44:26 PM1/26/20
to Jam.py Users Mailing List
ok, i can use set_where but...

What if the field I'm filtering is an id field of a lookup list. But instead of filtering by it's id, I want to filter by the name of the lookup list?

rrad

unread,
Jan 26, 2020, 3:48:35 PM1/26/20
to Jam.py Users Mailing List
Hi,
Okay, let's go in order

When you have a lookup box with a help button to its right, whichever you
choose will return two values, the id of the lookup item record and the lookup_value,
the value of the field you selected to display.

With on_field_select_value, you will filter the lookup item before it opens.
Jam.py will open and you will have a shortened dataset.

Of course you can search by the field you chose to display,
(not sure it makes sense to search by third) the story is the same,
incrementally searching with each character entered will shorten the dataset
and eventually the selected id and value of the display field will be returned.

Regards,
rrad

jimbo

unread,
Jan 26, 2020, 6:44:26 PM1/26/20
to Jam.py Users Mailing List
Yes I get that.

My question is that If the view contains a field that is a lookup to a lookup list, how would I use set_where to filter by the lookup list name versus its id?


lookup_item.set_where({lookup_list__contains : 'a text value'})

the framework expects this:

lookup_item.set_where({lookup_list__contains : an_id_of_the_list})

Andrew Yushev

unread,
Jan 27, 2020, 1:59:05 AM1/27/20
to jimbo, Jam.py Users Mailing List
Hello,

When when lookup field has lookup item, the contains filter filters lookup values.
When lookup field uses lookup list, you must filter by value not lookup value.

Regards

пн, 27 янв. 2020 г. в 02:44, jimbo <ji...@customermarketinggroup.com>:
--
You received this message because you are subscribed to the Google Groups "Jam.py Users Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jam-py+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jam-py/881eb7dd-a30c-4fbf-923b-e4ce5d2be6a3%40googlegroups.com.

rrad

unread,
Jan 27, 2020, 3:20:14 AM1/27/20
to Jam.py Users Mailing List
Hi,
Example from docs:

function
on_field_select_value(field, lookup_item) { if (field.field_name === 'customer') { lookup_item.set_where({lastname__startwith: 'B'}); lookup_item.view_options.fields = ['firstname', 'lastname', 'address', 'phone']; } }

Regards,
rrad

rrad

unread,
Jan 27, 2020, 3:31:08 AM1/27/20
to Jam.py Users Mailing List
HI,
If you want to filter lookup_list, it's a little different.

Example:
If we have item with example lookup_list, and we want to filter it:

    function on_edit_form_shown(item) {
        if (item) {
            item.event.lookup_values = task.lookup_lists[7].slice(2, 5);
        }
    }
   
   
    function on_edit_form_closed(item) {
        if (item) {
            item.event.lookup_values = task.lookup_lists[7];
            item.update_controls();                             
        }
    } 

Regards,
Radosav
To unsubscribe from this group and stop receiving emails from it, send an email to jam...@googlegroups.com.

jimbo

unread,
Jan 27, 2020, 7:42:31 AM1/27/20
to Jam.py Users Mailing List
fair enough.

Lookup Lists are static enough that we should know their key value, versus their textual name, so I understand the design decision.

That said, sometimes relying on keys (a lookup lists value)  is  unpredictable in certain use cases.

I would be great to update documentation on this nuance... where lookup items must be search by lookup value and lookup lists must be searched on their key value (value).

Just a suggestion.

rrad

unread,
Jan 27, 2020, 8:02:22 AM1/27/20
to Jam.py Users Mailing List
Hi,
Searching for a lookup list is a bit of a distraction at Jam.py.
Since these small classifiers are needed as well as large classifiers it seems to me that you are right.
But if I had a problem with searching for small classifiers, I would turn them into big ...

rrad

Danijel Kaurin

unread,
Feb 16, 2021, 3:10:00 PM2/16/21
to Jam.py Users Mailing List
Hi.

I'am trying to filter lookup list where records have 'true' value in field 'aktivno' (boolean type field). I'am using function:

function on_field_select_value(field, lookup_item) {
    if (field.field_name === 'radnomjesto') {
        lookup_item.set_where ({aktivno : true })
        lookup_item.view_options.fields = ['nazivrm', 'biljeska', 'aktivno'];
    }
}

and getting this error:

"Exception: operator does not exist: boolean = integer
LINE 1: ..."OpisRM" FROM "rmHrm" AS "rmHrm" WHERE "rmHrm"."Aktivno" = 1
                                                                    ^
HINT:  No operator matches the given name and argument types. You might need to add explicit type casts."

Drazen D. Babic

unread,
Feb 16, 2021, 8:56:49 PM2/16/21
to Jam.py Users Mailing List
Is this postgres? 

Please try to specify your environment so we do not need to guess :)

Thx

Danijel Kaurin

unread,
Feb 17, 2021, 2:11:43 AM2/17/21
to Jam.py Users Mailing List
Hi Drazen.

Sorry, yes this is Postgres on Windows mashine.

Andrew Yushev

unread,
Feb 17, 2021, 1:26:23 PM2/17/21
to Danijel Kaurin, Jam.py Users Mailing List
Hi, Danijel

It is hard to find the reason for the error.
Can you make a sample app?

Maybe it is because the on_field_select_value can be used to filter records when selecting value for lookup fields,
not lookup lists.

Regards,
Andrew Yushev

ср, 17 февр. 2021 г. в 10:11, Danijel Kaurin <yonika...@gmail.com>:
Message has been deleted

Danijel Kaurin

unread,
Feb 18, 2021, 3:11:19 AM2/18/21
to Jam.py Users Mailing List
Hi Andrew.

Here is some test project on link. In Sqlite db is everything ok, but in Postgres, i have error which I already sent.

So, in form "Employee" a wanto to show only City's who have  'true' value in column 'valid' in lookup table ''city". I used on_field_select_value and in Sqlite db it is working fine, try in Postgres.

Note: I'am using imported table from Access db.

Regards

Andrew Yushev

unread,
Feb 18, 2021, 1:20:38 PM2/18/21
to Danijel Kaurin, Jam.py Users Mailing List
Danijel, I created a project with a Postgres database and imported the project you sent.
It works ok.


чт, 18 февр. 2021 г. в 11:11, Danijel Kaurin <yonika...@gmail.com>:
--
You received this message because you are subscribed to the Google Groups "Jam.py Users Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jam-py+un...@googlegroups.com.
on_field_select.mp4

Danijel Kaurin

unread,
Feb 19, 2021, 9:58:56 AM2/19/21
to Jam.py Users Mailing List
Hi Andrew.

When you create new boolean type field from Jam.py App builder, then everything is ok. But when you create new boolean type field in Postgres PgAmin or using tables who are first imported in Postgres (like I'am), then you have some kind of incompatibility with boolean data type. Postgres then require type cast.

I'am new with Postgres so I will create new boolean field in Jam.py App builder and use that field in my on_field_select_value function .

Thank you for your time. 

Regards

r rad

unread,
Nov 10, 2025, 7:53:00 PMNov 10
to Jam.py Users Mailing List
I have to included, after many years.

I have similar behavior with PostgreSQL and Jam.py V5.
After 3 years in production program with Postgres return some as "Can't update with integer because field is boolean."

Did any got it steel?

Radosav

r rad

unread,
Nov 11, 2025, 6:44:29 PMNov 11
to Jam.py Users Mailing List
I don't know if there interesting, but I solved this problem.
For now this is on V5 version, but I will be do it and on V7 - if it is appeared!

Salute, Radosav.

Dean D. Babic

unread,
Nov 11, 2025, 8:00:29 PMNov 11
to Jam.py Users Mailing List
Thanks, so what was the fix?

r rad

unread,
Nov 12, 2025, 10:17:56 AMNov 12
to Jam.py Users Mailing List

Well, this was a little complicated!

My software work on V5.4.124. But, I am do patch on V5.4.136.

Files 

- sql.py - 4 changes, 

- server_classes.py - 1 change and 

- databse.py - 1 change, 

all of them, assigment value for boolean type of field. 

And one @staticmethod in SQL class of sql.py!

All in all, nothing so hard, but very complicated, because Jam.py runtime way.

I think, you are finished with support on version V, I will see on V7 how it doing.

Radosav

r rad

unread,
Nov 12, 2025, 11:34:58 AMNov 12
to Jam.py Users Mailing List

Patched code can be download from https://github.com/rrad0812/jam.py-v5.4.136-rrad.
Need to copy over files in root jam.py v5.4.136 package!
Enjoy it.

Radosav

Dean D. Babic

unread,
Nov 12, 2025, 8:23:39 PMNov 12
to Jam.py Users Mailing List
Thanks. Here are the files for v5
dataset.py
server_classes.py
sql.py
Reply all
Reply to author
Forward
0 new messages