elabx Posted August 23 Share Posted August 23 I had though of this hook: $wire->addHookBefore("ProcessPageEdit::buildFormContent", function ($event) { wire()->addHookBefore('Inputfield::render', function ($e) { $inputfield = $e->object; if (strpos($inputfield->name, "some_field") !== false && wire('modules')->SettingsModule->use_some_field == true) { $inputfield->label = "sample text"; $inputfield->collapsed = Inputfield::collapsedHidden; } }); }); I would have though that setting collapsed property before render would not allow the field to render. I want to handle some fields visibility in a settings module I use to manage enabling and disabling features in ProcessWire. An alternative strategy I do right now is that on the module save config I check for the module settings value and set the field to have it's input collapsed to hidden, but I'd like to think there is a more dynamic way at runtime? Does anybody have something like this working? Link to comment Share on other sites More sharing options...
monollonom Posted August 23 Share Posted August 23 I also had to set the collapsed property dynamically and thankfully @Robin S has got us covered ? Just replace the hook to be on Field::getInpufield and it should work. 1 Link to comment Share on other sites More sharing options...
bernhard Posted August 23 Share Posted August 23 Why do you add a hook inside the hook? Just grab the field and set the collapsed state: <?php $wire->addHookAfter("ProcessPageEdit::buildFormContent", function ($event) { $form = $event->return; $f = $form->get('some_field'); if($f) $f->collapsed = Inputfield::collapsedHidden; }); I think this should work. Note that I'm using addHookAfter, not before! 2 Link to comment Share on other sites More sharing options...
elabx Posted August 23 Author Share Posted August 23 5 hours ago, bernhard said: Why do you add a hook inside the hook? Just trying things! haha My thought was to have it all scoped within the page edit process, since Inputfield render could pontentialy happen all around? I have indeed done that hook you show buildFormContent() but in the current specific scenario the field is within a repeater so I cannot edit it on the main form. 5 hours ago, monollonom said: I also had to set the collapsed property dynamically and thankfully @Robin S has got us covered ? I think this is what I was looking for, fantastic! Although I see an interesting observation from @bernhard in that topic. Will give it a shot and come back! Thanks everyone! 3 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now