How to check pages field type
Closed this issue · 2 comments
Hi,
Can I check whether or not a value is present in a pages field type?
My field data looks like this:
Collections:
- page://Z2uqfbGTBHGLxL6r
- page://pw6knY6mFDFOUNp2
- page://pnYRkaUdzI9usTv5
I'm not sure how to check if one the values is present. Will the data be passed as an array?
collections ::filter($ = 'page://pnYRkaUdzI9usTv5') =~ 'page://pnYRkaUdzI9usTv5'
This is how in case anyone needs it:
collections ::map($.text) =~ 'Trials'
"Trials" being the name of the page.
That's one way :)
collection ::any($.text = 'Trials')
might be slightly faster (because it returns early if it finds a matching entry).
Or if you want to match by id:
collections ::any($.uuid = 'page://pnYRkaUdzI9usTv5')
I get where the confusion comes from, the values you have in the content file don't always match the values you get from the fields in the panel. You can inspect what the "values" are in the panel by running
panel.app.$store.getters["content/values"]()
in the browsers JS console. For a pages field it would look something like this: