Jump to content

\IPS\Helpers\Form::addHeader - Ability to toggle


Go to solution Solved by teraßyte,

Recommended Posts

This might not be a bug per se, but something that could be clarified via some comments in the code for addHeader maybe?

I'm working on an app which would allow an entire section to be toggled on or off.

Part of this involves hiding a section header (via a YesNo for example) by its assigned ID.

When I tried doing:

        $form = new \IPS\Helpers\Form;
        $form->add(new \IPS\Helpers\Form\YesNo('yesno_toggle', FALSE, FALSE, array('togglesOn' => array('my_header', 'text_field',)), NULL, NULL, NULL, 'yesno_toggle'));
        $form->addHeader('my_header',NULL,NULL,'my_header');
        $form->add( new \IPS\Helpers\Form\Text( 'text_field', NULL, FALSE, array( 'placeholder' => 'Enter some text here' ), NULL, NULL, NULL, 'text_field' ) );

It did not work, however when I changed 'my_header' to 'form_header_my_header' in the 'togglesOn' list, it worked.

        $form = new \IPS\Helpers\Form;
        $form->add(new \IPS\Helpers\Form\YesNo('yesno_toggle', FALSE, FALSE, array('togglesOn' => array('form_header_my_header', 'text_field',)), NULL, NULL, NULL, 'yesno_toggle'));
        $form->addHeader('my_header',NULL,NULL,'my_header');
        $form->add( new \IPS\Helpers\Form\Text( 'text_field', NULL, FALSE, array( 'placeholder' => 'Enter some text here' ), NULL, NULL, NULL, 'text_field' ) );

When toggling other form elements, just using the assigned ID works, so I feel like this should follow suit without the manually-added prefix.  Its also of concern that it wasn't clear this was necessary.

Maybe anything in a "togglesOn/togglesOff/toggles" array could be run through something that checks whether the id ties back to a form header or not, and applies the prefix automatically? 

 

I actually set out to report this as a bug with addHeader toggling simply not working, but in typing it up I realized what was actually going on and modified this post.  Its funny how many things can be solved on your own by trying to tell someone about it. 😅

Link to comment
Share on other sites

  • Solution

The problem here is that actually the addHeader() function doesn't have a 4th parameter to pass the ID. The ID is hardcoded to use the form id together with the header string and the name you provide as the 1st parameter instead:

	public function addHeader( $lang, $after=NULL, $tab=NULL )
	{
		/* Place the input into the correct position */
		$this->_insert( \IPS\Theme::i()->getTemplate( 'forms', 'core' )->header( $lang, "{$this->id}_header_{$lang}" ), NULL, $tab, $after );
	}

 

So yeah, not exactly a bug. It would be nice it IPS allows to pass a custom ID as 4th parameter just like the other form helpers though.

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Upcoming Events

    No upcoming events found
×
×
  • Create New...