processwire / processwire-issues

ProcessWire issue reports.
45 stars 2 forks source link

"Blank" visibility options that work for fieldset are missing from field config #1953

Open Toutouwai opened 4 months ago

Toutouwai commented 4 months ago

Short description of the issue

In earlier versions of PW the full range of options were available for the Visibility > Presentation setting for FieldtypeFieldsetOpen fields.

The screenshot below is from PW 3.0.118

2024-07-25_194500

At some point many of these options were removed from InputfieldWrapper, which InputfieldFieldsetOpen extends.

2024-07-25_194654

But the four options relating to blank/populated are useful and they seem to work fine with FieldtypeFieldsetOpen. If I restore those options with the hook below...

$wire->addHookAfter('InputfieldFieldsetOpen::getConfigInputfields', function(HookEvent $event) {
    $inputfield = $event->object;
    $wrapper = $event->return;
    // Not for InputfieldFieldsetTabOpen
    if($inputfield instanceof InputfieldFieldsetTabOpen) return;
    $f = $wrapper->getChildByName('collapsed');
    if(!$f) return;

    // Add back the blank/populated options that were removed by InputfieldWrapper::getConfigInputfields
    $f->addOption(Inputfield::collapsedBlank, $this->_('Open when populated + Closed when blank'));
    if($inputfield->hasFieldtype !== false) {
        $f->addOption(Inputfield::collapsedBlankAjax, $this->_('Open when populated + Closed when blank + Load only when opened (AJAX)') . " †");
    }
    $f->addOption(Inputfield::collapsedBlankLocked, $this->_('Open when populated + Closed when blank + Locked (not editable)'));
    $f->addOption(Inputfield::collapsedPopulated, $this->_('Open when blank + Closed when populated'));
});

...then the fieldset can be automatically collapsed or not based on whether the child fields are populated.

Seeing as this works, was the removal for FieldtypeFieldsetOpen unintended? Can support for these visibility settings be added back please?

Setup/Environment

Toutouwai commented 3 months ago

I think Inputfield::collapsedHidden should also be allowed for FieldtypeFieldsetOpen, as this also seems to work fine and it's a useful option.

ryancramerdesign commented 3 months ago

If I recall correctly, these options were removed because they can work in most cases, but not in all cases. So only the visibility options that are guaranteed to always work are shown. If you'd like, I could make the others available in config.advanced mode though, where this type of inconsistency is more expected.

Toutouwai commented 2 months ago

If I recall correctly, these options were removed because they can work in most cases, but not in all cases.

The options were removed in this commit, which doesn't seem to be in response to a bug report.

Perhaps the impact on fieldsets from changes to InputfieldWrapper was just an oversight, as some functionality was previously restored in response to another issue: https://github.com/processwire/processwire-issues/issues/1603

In my testing the visibility settings mentioned above seem to work without issues so it would be good to have them available without having to enable advanced mode.