Jump to content

Visibility for custom fields of images [SOLVED]


mel47
 Share

Recommended Posts

Posted (edited)

Hi,
I want to show some custom fields from an image depending on the page id. However just a showIf = parent.id=1042 doesn't work. (1042 is the page, not the image)

Is it possible by a different syntax?

Thanks

Mel

Edited by mel47
SOLVED - update of module by RobinS
Link to comment
Share on other sites

Hello,
That was my first guest, but it didn't work. However it finds the good page. But then, the field is not appearing.
image.thumb.png.7d36a75268089debbb038fe570b41153.png


Image from page 1042 is without publication_date field :

image.thumb.png.af0c3d0abf2a3e669377df89804377d5.png

I'm not sure if I don't have the good syntax or if it's a limitation?
Thanks.

Link to comment
Share on other sites

@mel47, currently the PW core does not support showIf or requiredIf in custom fields for files/images. See this issue: https://github.com/processwire/processwire-issues/issues/1889

And even if that issue is resolved, the way the core is handling showIf/requiredIf at the moment means that it will only evaluate the showIf/requiredIf based on values of other custom fields for the image/file item, not fields in the page that is open in Page Edit.

But I've just updated the CustomInputfieldDependencies module so that it should handle your case. Please update the module to v0.3.0 and test it again.

  • Like 5
  • Thanks 1
Link to comment
Share on other sites

  • mel47 changed the title to Visibility for custom fields of images [SOLVED]

I came across this problem and solved it with a hook. In my case, I use the image field in 2 different repeaters and needed a dependency on the template. Field names of custom image fields always contain the ID of the page or repeater page to which the image field is assigned.

e.g. "image_caption_image_repeater18596_9cc494cc88e6dc55046f042aa5b3492d" whereas 18596 is the page / repeater page id

   wire()->addHookAfter('InputfieldWrapper::renderInputfield', function($e) {
        $inputfield = $e->arguments[0];
        if (strpos($inputfield->name, 'image_caption_image_repeater') === 0) {
            $pid = (int) strstr(substr($inputfield->name, strlen('image_caption_image_repeater')), '_', true);
            $tn = wire('pages')->get($pid)->template->name;
            if ($tn == "repeater_cards") $e->return = '';
        }
    });

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...