diff --git a/DynamicContainer.php b/DynamicContainer.php index 18a9f28..a36cdb6 100644 --- a/DynamicContainer.php +++ b/DynamicContainer.php @@ -151,6 +151,8 @@ protected function createRow($name = null) { if ($this->useAjax) $button->getControlPrototype()->class($this->ajaxClass); } + + return $innerContainer; } /** diff --git a/DynamicContainerCore.php b/DynamicContainerCore.php index 11e31bc..f3cd45a 100644 --- a/DynamicContainerCore.php +++ b/DynamicContainerCore.php @@ -270,6 +270,23 @@ protected function fireOnChange() { // + + /** + * Override: set values for this container while adding rows for it + * (needs https://github.com/nette/nette/pull/217 implemented in Nette) + * + * @param array $values + * @param bool $erase + * @return void + */ + public function setValues($values, $erase = FALSE) { + $this->clearRows(); + foreach($values as $key => $sub) { + $this->createRow($key)->setValues($sub, $erase); + } + } + + // public static function FormContainer_addDynamicContainerCore(FormContainer $_this, $name = null, $factoryCallback = null) { diff --git a/FormMacros.php b/FormMacros.php index 6770497..dc890e1 100644 --- a/FormMacros.php +++ b/FormMacros.php @@ -129,6 +129,17 @@ public static function input($name, $modifiers) { echo $input; } + public static function macroPair($content) { + list($name, $modifiers) = self::fetchNameAndModifiers($content); + return "Addons\Forms\FormMacros::pair($name, $modifiers)"; + } + public static function pair($name, $modifiers) { + $control = self::getControl($name); + echo self::getForm()->getRenderer()->renderPair($control); + } + + + // // @@ -162,7 +173,11 @@ public static function inputValue($name, $modifiers = array()) { public static function macroBeginDynamicContainer($content) { list($name) = self::fetchNameAndModifiers($content); - return '$dynamicContainers = Addons\Forms\FormMacros::getControl('.$name.')->getComponents(); Addons\Forms\FormMacros::beginContainer('.$name.'); foreach($dynamicContainers as $dynamicContainerName => $dynamicContainer): Addons\Forms\FormMacros::beginContainer($dynamicContainerName);'; + return + '$dynamicContainers = Addons\Forms\FormMacros::getControl('.$name.')->getComponents(); + Addons\Forms\FormMacros::beginContainer('.$name.'); + foreach($dynamicContainers as $dynamicContainerName => $dynamicContainer): + Addons\Forms\FormMacros::beginContainer($dynamicContainerName);'; } public static function macroEndDynamicContainer($content) { return "Addons\Forms\FormMacros::endContainer(); endforeach; Addons\Forms\FormMacros::endContainer();"; @@ -178,6 +193,7 @@ public static function register() { LatteMacros::$defaultMacros["formErrors"] = ''; + LatteMacros::$defaultMacros["pair"] = ''; LatteMacros::$defaultMacros["input"] = ''; LatteMacros::$defaultMacros["label"] = ''; LatteMacros::$defaultMacros["inputValue"] = '';