PWaddict Posted November 14, 2017 Share Posted November 14, 2017 Is it possible to change the Notes of a field with a Hook? The field belongs to a PageTable. Link to comment Share on other sites More sharing options...
bernhard Posted November 14, 2017 Share Posted November 14, 2017 yes Spoiler // site/ready.php $wire->addHookBefore('Inputfield::render', function(HookEvent $event) { $field = $event->object; if($field->name != 'yourfield') return; $field->entityEncodeText = false; $field->notes = 'this is <strong>UNTESTED</strong>'; }); 4 Link to comment Share on other sites More sharing options...
adrian Posted November 14, 2017 Share Posted November 14, 2017 The other option is: http://modules.processwire.com/modules/dynamic-description-notes/ 2 Link to comment Share on other sites More sharing options...
PWaddict Posted November 15, 2017 Author Share Posted November 15, 2017 11 hours ago, bernhard said: yes Hide contents // site/ready.php $wire->addHookBefore('Inputfield::render', function(HookEvent $event) { $field = $event->object; if($field->name != 'yourfield') return; $field->entityEncodeText = false; $field->notes = 'this is <strong>UNTESTED</strong>'; }); It works great. Thank you. I hope you can help me with 1 more thing: The field belongs to a PageTable. That PageTable is used under 2 different templates: template1 & template2. I want to change the field notes ONLY for template2. Link to comment Share on other sites More sharing options...
PWaddict Posted November 15, 2017 Author Share Posted November 15, 2017 I figured how to do it: $wire->addHookBefore('Inputfield::render', function(HookEvent $event) { $field = $event->object; if($field->name != 'myfield') return; $page = $this->process->getPage(); $parent = $page->parent(); if ($parent->template->name == "mytemplate") { $field->entityEncodeText = false; $field->notes = 'My new notes!'; } }); Please correct me if I did something wrong. 2 Link to comment Share on other sites More sharing options...
PWaddict Posted November 17, 2017 Author Share Posted November 17, 2017 How can I do the same thing on a field that belongs to a repeater??? Link to comment Share on other sites More sharing options...
bernhard Posted November 17, 2017 Share Posted November 17, 2017 ok didn't know there is a difference. if you do not do already i recommend using adrians awesome tracy debugger module. then you see that inside a repeader the field has a different name: $wire->addHookBefore('Inputfield::render', function(HookEvent $event) { $field = $event->object; bd($field->name); }); hope that helps and you find your solution on your own i'm busy 2 Link to comment Share on other sites More sharing options...
Robin S Posted November 17, 2017 Share Posted November 17, 2017 19 hours ago, PWaddict said: How can I do the same thing on a field that belongs to a repeater??? Easiest way that works for inputfields both inside and outside of repeaters is to match the name of the field associated with the inputfield: $wire->addHookBefore('Inputfield::render', function(HookEvent $event) { $inputfield = $event->object; if($inputfield->hasField == 'YOUR_FIELD_NAME') { //... 4 Link to comment Share on other sites More sharing options...
PWaddict Posted November 17, 2017 Author Share Posted November 17, 2017 Here is the solution: $wire->addHookBefore('Inputfield::render', function(HookEvent $event) { $field = $event->object; $page = $this->process->getPage(); if($field->hasField == 'myfield' && $page->template->name == "mytemplate") { $field->entityEncodeText = false; $field->notes = 'My new notes!'; } }); Thanks for your tips. Link to comment Share on other sites More sharing options...
PWaddict Posted November 18, 2017 Author Share Posted November 18, 2017 Now I cannot access Setup > Templates. I'm getting this error: ProcessWire: ProcessTemplate: Method ProcessTemplate::getPage does not exist or is not callable in this context. Link to comment Share on other sites More sharing options...
Robin S Posted November 18, 2017 Share Posted November 18, 2017 3 minutes ago, PWaddict said: Now I cannot access Setup > Templates. $wire->addHookBefore('Inputfield::render', function(HookEvent $event) { $field = $event->object; if($this->process != 'ProcessPageEdit') return; $page = $this->process->getPage(); //... BTW, it would be better to hook a more specific inputfield render rather than just Inputfield::render. So something like InputfieldPageTable::render or whatever inputfield type you are targeting. 3 Link to comment Share on other sites More sharing options...
PWaddict Posted November 18, 2017 Author Share Posted November 18, 2017 23 minutes ago, Robin S said: BTW, it would be better to hook a more specific inputfield render rather than just Inputfield::render. So something like InputfieldPageTable::render or whatever inputfield type you are targeting. I replaced Inputfield::render with InputfieldRepeater::render but it doesn't work. Link to comment Share on other sites More sharing options...
bernhard Posted November 18, 2017 Share Posted November 18, 2017 10 hours ago, PWaddict said: I replaced Inputfield::render with InputfieldRepeater::render but it doesn't work. you need to use the classname of the inputfield that you are modifying. your field is inside a repeater, but it is not a repeater itself. if it is a textfield you have to use InputfieldText, if it was a checkbox it would have to be InputfieldCheckbox. Also $field->entityEncodeText = false; is only necessary if you want to use markup in your note 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