Jump to content

[SOLVED MYSELF] $inputfield->notes not displayed on InputfieldSelect using PageReferences


cwsoft
 Share

Recommended Posts

Posted (edited)

Hi,

I have a hook, which disables some input fields and shows a note, why the input field is disabled. This seems to work fine just with one exception. When I have a InputfieldSelect with PageReferences as items, I can disable the select field, but the notes don't show up below the input field. It works fine for Select Options or other Inputfields like Datetime, Text etc. So I am a bit puzzled why my notes don't show up for PageReferences only.

$wire->addHookBefore('InputfieldSelect::render', function (HookEvent $event) {
    $inputfield = $event->object;
    $page = $inputfield->hasPage;
    $field = $inputfield->hasField;

    // Limit to certain templates and fields.
    if (!$page || !$field) return;
    if (!$page->className === 'MyPageClass' || !in_array($field->name, ['hotel', 'branch'])) return;

    // Disable inputfield and show a notice to the user.
	$inputfield->addClass = 'uk-disabled';
    $fieldInfo = $field->name === 'hotel' ? 'Hotel' : 'Branch';
    $inputfield->notes("$fieldInfo can't be modified.");
});

Both select input fields gets disabled, which is what I want, but the notes are only showing for the field branch, which stores Select Options. However no notes are shown for the field hotel, which stores Page References. Both fields are InputfieldSelect fields, but one storing options, the other page references.

If I do a bd($inputfield), I can see that for the hotel field (with page references), there exists no parent (InputfieldWrapper), but for the field branch it's there.

Output from bd($inputfield): 
parent: array(3)
   'className' => 'InputfieldWrapper'
   'name' => ''
   'id' => 'InputfieldWrapper31'

Does anybody have a glue, whats going on here? As mentioned, the note is shown fine for all Inputfield types (e.g. Text, Datetime, SelectOptions) except for PageReferences. Is there any other way you guys can think of how I could add a note below the inputfield, if the $inputfield->notes() method does not work? By the way. The notes text is shown just fine in the data section (bd) for both. Guess it must be related to the missing parent, which is the InputfieldWrapper.

Any hints welcome.

P.S.: This behavior is identical for both, the actual master and the actual dev branch and has nothing to do with the redesigned admin theme.

Edited by cwsoft
Fixed topic text
Link to comment
Share on other sites

  • cwsoft changed the title to [SOLVED MYSELF] $inputfield->notes not displayed on InputfieldSelect using PageReferences
Posted (edited)

Solved the issue myself thanks to Tracy Debugger and the handy bd() method. While inspecting the methods using bd($inputfield) I found a property called "hasInputfield" in the $inputfield storing the Page references. So I added the following lines at the end of the code in my initial post to set the notes on the nested inputfield which stores the Page References.

if ($field->name === 'hotel') {
        $nestedInputfield = $inputfield->hasInputfield;
        $nestedInputfield->notes("$fieldInfo can't be modified.");
}

The class however needed to be set to the outer inputfield to disable the inputfield to prevent user actions on it.

Edited by cwsoft
  • Like 1
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...