I have the following fieldset configuration and the hero_poster field is not showing up.
hero_media:
container: assets
mode: grid
restrict: false
allow_uploads: true
max_files: 1
type: assets
localizable: false
listable: hidden
width: 50
display: Image/Video
hero_poster:
container: assets
mode: grid
restrict: false
allow_uploads: true
max_files: 1
type: assets
localizable: false
listable: hidden
display: Poster
width: 50
if:
hero_media: includes mp4
I tried all of the following, but no luck:
if:
hero_media: includes mp4
if:
hero_media: 'includes mp4'
if:
hero_media: contains mp4
if:
hero_media: 'contains mp4'
You're doing it right, any of those should probably work. Looks like a bug.
This was the issue that inspired the field condition changes introduced in beta 23. Pretty sure this can be closed.
Still happening for me though, I can't get a condition to hit successfully.
Ah it's because contains mp4 would be checking if the value (an array of asset ids, like [foo.mp4, bar.jpg] contains mp4.
Might make a little more sense if you wrote it in php:
in_array('mp4', ['foo.mp4', 'bar.mp4']) // false
We'd need to check if any value has a substring of mp4. Looks like a little custom js condition would be the way to go for now.
if:
hero_media: 'custom containsExtension:mp4'
Statamic.$conditions.add('containsExtension', ({ target, params }) => {
const extension = params[0];
return _.some(target, value => value.endsWith(`.${extension}`));
});
^ That. You could also...
if:
hero_media: 'custom isFiletype:jpg,png'
Statamic.$conditions.add('isFiletype', ({ target, params }) => {
return new RegExp(params.join('|') + '$').test(target[0]);
});
Assuming your assets field is max_files: 1 (as in your fieldset example), this would show the field if the asset extension is either jpg or png.