I'm editing this with the simplest setup I found to replicate the issue.
Drop a text field and a table in a view.
Copy the table's default data to a custom property.
Now structure-bind the table's
prop.data property to both the text field
prop.text and the custom property holding the data.
Add a script transform with this:
lambda item: value.filter_text in item['city'],
value.data is the data from the custom property and
value.filter_text is the text field's value.
Run the preview, and type things in the text field. You'll see the table being updated, with entries that don't match filtered out.
So far so good, everything works just fine.
Now add columns to the
props.columns property of the table.
If you try again now, it still works just fine.
Now set the
field property of a column to
If you try now, typing things in the text field filters rows out of the table. When the table is empty because nothing matches anymore, the text field just stops working. It still has focus, but typing doesn't do anything.
Note that whatever column you "name", the same thing happen. You could be filtering on 'city' but only name the 'country' column, it still boinks up.
Note also that this issue appears to be chromium related, as it doesn't happen with Firefox... But Brave, Chrome and Edge all had that behavior.
Below is the original post, I'll leave it there just in case.
I'm having a bit of an issue with the text field. It loses focus when I don't want it to.
I suspect it happens when bindings on other components are evaluated.
I'm building a dynamic search thingie to filter a table.
For each filterable column, there's a filter field.
Let's say I have a column
name, and a filter field for that column. Typing things in that field will filter out any row where the value in the column
name doesn't contain what's in the filter.
This works well, but when the table is updated because I typed a new character that triggers a filter, the text field loses focus.
NOTE: This only happens when ADDING a character, not deleting one.
Let's see with pictures:
Text field has focus.
Nothing changed in the table, text field still has focus.
Added a 5, my row was filtered out, text field lost focus (despite still having the blue border, which would suggest it's still selected)
deleted 5, row came back in the table, text field still has focus.
It makes it very unpleasant to use... Any way I can work around this ?
I have another version of this that requires a button click to apply the filters, just in case I can't solve this reliably, but I'd rather have the auto-update.
edit: I just realized I might have been on the sparse side concerning details.
So here's what goes on:
- The filter fields are in a flex repeater.The repeated view has an output parameter called 'value', and a parameter called 'field_name' that corresponds to the column name.
- The table's
dataproperty has a structure binding, that takes the base data and the filters
- The base data is a list of objects, not a dataset, because it's itself built through a transform putting together several tables.
- The binding has a script transform that filters things out of the data based on the filters.
In case it's relevant, or someone has a better method for this, here's the transform.
from java.util import ArrayList
def check_filter(item, f):
if isinstance(f.value, (ArrayList, list)):
return any(str(item[f.field_name]) == str(elem) for elem in f.value)
return str(f.value) in str(item[f.field_name])
lambda item: all(check_filter(item, f) for f in value.filters),
Version is 8.1.17 and that cannot change.
Actually, it doesn't lose focus. Adding some logging on the
onBlur event reveals that the focus is not lost. The text field just stops text fielding until it's clicked again...