Filter repeater with search term

repeater-widget

#1

I have figured out how to filter my repeater on the text changed interaction to give me results displayed in a table:

[[Item.CaseNumber.indexOf(this.text) > -1]]

However, I do not know how to reverse this behaviour when the text field is empty.

I understand that we can remove filters but the official examples only show removing with a button to trigger the action. I need to show all data when a user deletes the search term from the text field.


#2

Hi!

Change your filter to this. (Those are two single quotes.)

[[This.text == '' || Item.CaseNumber.indexOf(this.text) > -1]]

This says, in English, “Show each row if the search field is blank OR if the search field matches the row.” (The double-pipe means OR.)

A filter is applied to the repeater row-by-row, and shows a given row when it evaluates as true and doesn’t show the row if it evaluates as false.

You can put multiple true/false tests in a single filter by separating them with ANDs (&&) or ORs (||), or a combination of both. When two such tests are OR’ed together, as in this case, only one of them needs to be true for the whole filter to be true.

When the field is blank, the first true/false test in the filter above evaluates as TRUE for each row no matter what the row contains because it does not refer to anything in the row itself. And when the field is blank it doesn’t matter whether the second test evaluates to true or not: just one test needs to be true because of the OR. So all rows are shown when the field is blank.


#3

Hi.

Thanks for the quick reply. I tried this but when i delete the search term the repeater displays nothing as if there are no results.

[[This.text == ‘‘ || Item.CaseNumber.indexOf(This.text) > -1]]

Not sure why.


#4

Hi!

It’s because you have smart quotes on. Your two quotation marks are slanted instead of straight, and Axure’s filter doesn’t recognize them as sinqle quotes.

Turn off smart quotes. It’s under keyboard preferences on the Mac. Not sure where in Windows.


#5

I turned of smart quotes but it seems the same:

[[This.text == '' || Item.CaseNumber.indexOf(This.text) > -1]]

I really appreciate your help but am not sure what could be going on.


#6

Weird. Everything looks good, assuming the script is assigned to the field itself and not a button, since This refers to the thing that owns the script.

Make sure there’s not a space outside of the double brackets. Also, if you are using hint text in the field, try removing it, as there was at one time a bug where This.text returned hint text.

If you are still having an issue, maybe post the file.


#7

It was the hint text!

Thanks so much for giving up your time to help with this matter.