[FLOW3-general] How to set/get/show M:N relations using checkboxes instead of selectbox?

Manfred Rutschmann - VOLUMEN Werbe-/Internetagentur rutschmann at agentur-volumen.de
Sat Mar 9 18:52:56 CET 2013


Hey, whats about the jquery ui miltiple select with checkboxes widget?

http://www.erichynds.com/jquery/jquery-ui-multiselect-widget/

Manfred

Am 08.03.2013 um 20:12 schrieb Stephen Bungert <stephenbungert at yahoo.de>:

> Hi.
> 
> I needed to do this to.
> 
> I have books and these ccan be related to genres.
> 
> I render a list of genres with checboxes. I created this viewHelper to render the checkboxes checked attribute:
> 
> Maybe not the best way, but it may help you too.
> 
> Stephen.
> 
> <?php
> namespace Gamebook\Gamebook\ViewHelpers\Form;
> 
> /*                                                                        *
> * This script belongs to the TYPO3 Flow package "Gamebook.Gamebook".     *
> *                                                                        *
> *    */
> 
> use TYPO3\Flow\Annotations as Flow;
> 
> /**
> * This ViewHelper decides if a checkbox/radio should be checked.
> *
> * = Examples =
> *
> * <code title="Example">
> *	<f:form.checkbox checked="{gb:form.checked(record: genre, selectedRecords: book.genres)}" name="genresToAttach[genre]" value="{genre}" />
> * </code>
> * <output>
> * 	<input type="checkbox" checked="checked" value="6fa1d167-8ab6-4dd6-8099-202dd951fc3c" name="genresToAttach[genre][__identity]">
> * </output>
> */
> class CheckedViewHelper extends \TYPO3\Fluid\Core\ViewHelper\AbstractViewHelper {
> 
> 	/**
> 	 * @Flow\Inject
> 	 * @var \TYPO3\Flow\Persistence\PersistenceManagerInterface
> 	 */
> 	protected $persistenceManager;
> 
> 	/**
> 	 * Returns the attribute value for the 'checked' attribute in radio and checkboxes.
> 	 *
> 	 * @param object $record The record to check against to see if it should be checked or not.
> 	 * @param \Doctrine\ORM\PersistentCollection $selectedRecords All the selected records that the parent record has selected.
> 	 * @return string $checkedState The value for the attribute 'checked' in a checkbox or radio.
> 	 */
> 	public function render($record, \Doctrine\ORM\PersistentCollection $selectedRecords) {
> 		$checkedState = '';
> 		
> 		if (is_object($record) && !empty($selectedRecords))
> 		{
> 			$recordIdentity = $this->persistenceManager->getIdentifierByObject($record);
> 			
> 			foreach ($selectedRecords as $possibleMatch) {
> 				if ($recordIdentity == $this->persistenceManager->getIdentifierByObject($possibleMatch))
> 				{
> 					$checkedState = 'checked';
> 					break;
> 				}
> 			}
> 		}
> 		
> 		return $checkedState;
> 	}
> }
> 
> ?>
> _______________________________________________
> FLOW3-general mailing list
> FLOW3-general at lists.typo3.org
> http://lists.typo3.org/cgi-bin/mailman/listinfo/flow3-general



More information about the FLOW3-general mailing list