processwire-issues icon indicating copy to clipboard operation
processwire-issues copied to clipboard

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

Open Toutouwai opened this issue 1 year ago • 3 comments

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

  • ProcessWire version: 3.0.240

Toutouwai avatar Jul 25 '24 07:07 Toutouwai

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

Toutouwai avatar Aug 14 '24 08:08 Toutouwai

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.

ryancramerdesign avatar Aug 16 '24 13:08 ryancramerdesign

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.

Toutouwai avatar Aug 25 '24 01:08 Toutouwai

@Toutouwai I have added them back. I'm not confident they all work in all cases, so may end up having to reduce the whitelist when/if reports come in that there are issues with any of them.

ryancramerdesign avatar Dec 27 '24 17:12 ryancramerdesign