Jump to content

Inputfield Dependencies: Hide field by path


sarah_hue
 Share

Recommended Posts

Hi,

still amazed by the possibilities of Inputfield Dependencies, but haven't quite figured out how to use it:

There's pages in different paths:

  • Home
    • Nobel prize
      • Literature
        • 2012
          • Page 1
          • Page 2
          • ...
      • Economics
        • 2012
        • 2011
          • Page 1
          • Page 2
          • ...

Yeah, I know, this structure doesn't make much sense at first sight. But trust me, it's elaborated. ;-)

Now I've used one single template for Page 1, Page 2, etc. and it needs to be all the same. Only the field "topic" is different: I need it to be shown for pages in /nobel-prize/literature/..., but hidden for all other pages (like the ones in /nobel-prize/economics/...). So I put

path%='literature'

as a "Show this field only if"-condition. Doesn't work. What did I misunderstand?

Thanks a lot

Sarah

Link to comment
Share on other sites

I believe it only can used with field=value, not with path or parent.

Conditions are expressed with a "field=value"

So, one may define and add a hidden field to that template and hook into page::saveready and populate this field with a true or false value regarding if the current page has that parent or not.

my_hidden_field=1

If you want to go that road we can show some examples how to achieve that.

  • Like 1
Link to comment
Share on other sites

had the same problem some days ago - clever trick with the hidden field! thank you horst :)

but wouldn't "saveready" be too late for populating the field? shouldnt it be populated at the very first impression of the form?

Link to comment
Share on other sites

So I put

path%='literature'

as a "Show this field only if"-condition. Doesn't work. What did I misunderstand?

Inputfield dependencies are evaluated by javascript only, that's why the api selectors do not work. The only information the dependency can evaluate are the values of the present form fields. It even does not work if a field is set to not editable, because in this case the value is not rendered as form field.

Shouldnt it be populated at the very first impression of the form?

The first impression of the form is after the first saveReady hook, as each page is created/saved right after you submitted the page name. 

  • Like 2
Link to comment
Share on other sites

  • 11 months later...

I believe it only can used with field=value, not with path or parent.

So, one may define and add a hidden field to that template and hook into page::saveready and populate this field with a true or false value regarding if the current page has that parent or not.

my_hidden_field=1

If you want to go that road we can show some examples how to achieve that.

Hello - I am new to ProcessWire and would like to go that way !

Defining the hidden field is no problem.

But where to hook into page::saveready ?

Example would be very appreciated!

Link to comment
Share on other sites

  • 2 months later...

I believe it only can used with field=value, not with path or parent.

So, one may define and add a hidden field to that template and hook into page::saveready and populate this field with a true or false value regarding if the current page has that parent or not.

my_hidden_field=1

If you want to go that road we can show some examples how to achieve that.

Can you expand on this answer at all? Thanks!

Link to comment
Share on other sites

I believe this is working; the field 'article_detail_parent' will be hidden and checked if the parent_id of the page I am editing matches that. Then I can use the ShowIf field to state if article_detail_parent=1 then only show X

$pages->addHookAfter('Pages::saveReady', function($event) {
    $page = $event->arguments('page');
    if ($page->parent_id == 1043) {
        $page->article_detail_parent = 1;
    }
});

Only issue is that setting this field to hidden removes it (rather than visibility:hidden; which I'm assuming would retain the value?)

Only way I found to do this was to include a separate stylesheet in admin.php and set the visibility:hidden and height:0.

This all seems way over the top to simply not show a field based on the parent?

Link to comment
Share on other sites

  • 11 months later...

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

×
×
  • Create New...