Jump to content

Is there a way to open fieldset inside module configuration if a an error occurs in one field inside this fieldset [SOLVED]


Juergen
 Share

Recommended Posts

Hello @all

I have a configurable module and for better overview i have created a lot of fieldsets where I have placed configuration fields inside. By default all fieldsets are closed.

So if an error occurs in one field after saving the module, I get the error message at the top, but the fieldset which includes the field with the error keeps closed. This is not very userfriendly, because you will not know in which of the fieldsets is the field which causes the error (I know, where to look, but someon who does not know my module will not...)

So it would be great if the fieldset with the error field inside will be opened, after the form processing.

Is there an inbuilt way to achive this or has someone struggled with the same problem and has found a working solution and will be so kind to post it here?

Thanks in advance

  • Like 1
Link to comment
Share on other sites

Hi @Juergen

Just tested and in my setup, if there are any nested fields in the fieldset with an error the parent fieldset is get automatically opened. From what I see in the code it is the intended behavior  https://github.com/processwire/processwire/blob/master/wire/core/InputfieldWrapper.php#L777

In any case you can manually set collapsed state of inputfields inside the getModuleConfigInputfields

public function getModuleConfigInputfields(array $data) {
		
		....

		foreach ($inputfields->getErrorInputfields() as $inputfield) {
			$inputfield->collapsed = Inputfield::collapsedNo;
		}
		
		return $inputfields;
	}

or even like this 

public function getModuleConfigInputfields(array $data) {
		
		....

		foreach ($inputfields->getErrorInputfields() as $inputfield) {
			$inputfield->collapsed = Inputfield::collapsedNo;
			$parents = $inputfield->getParents();
			
			foreach ($parents as $parent) {
				$parent->collapsed = Inputfield::collapsedNo;
			}	
		}
		
		return $inputfields;
	}

 

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

43 minutes ago, Zeka said:
public function getModuleConfigInputfields(array $data) {
		
		....

		foreach ($inputfields->getErrorInputfields() as $inputfield) {
			$inputfield->collapsed = Inputfield::collapsedNo;
			$parents = $inputfield->getParents();
			
			foreach ($parents as $parent) {
				$parent->collapsed = Inputfield::collapsedNo;
			}	
		}
		
		return $inputfields;
	}

This works!!! Thank you so much!!!

I can confirm, that the fieldset was always closed in my case. Maybe it has something to do, that the error was produced by a custom inputfield validator via a Hook.

Best regards Jürgen

  • Like 1
Link to comment
Share on other sites

  • Juergen changed the title to Is there a way to open fieldset inside module configuration if a an error occurs in one field inside this fieldset [SOLVED]

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...