rasteiner / k3-whenquery

Conditionally show fields and sections. Better.
MIT License
64 stars 1 forks source link

How to check pages field type #18

Closed Small-Systems closed 1 year ago

Small-Systems commented 1 year ago

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'

Small-Systems commented 1 year ago

This is how in case anyone needs it:

collections ::map($.text) =~ 'Trials'

"Trials" being the name of the page.

rasteiner commented 1 year ago

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:

image