From cb9c0b699698a1a582996c14811a704469f0448b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Oli=C5=A1ar?= Date: Mon, 26 Oct 2015 18:06:29 +0100 Subject: [PATCH] Better error exeption for editable column wrong value MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Pokud se nastaví sloupec na `editable` a value obsahuje objekt, který nelze konvertovat na string, vrací Grido nic neříkající chybu (např.): ``` Recoverable Error Object of class DateTime could not be converted to string ``` Po úpravě vrátí: ``` Exception Column 'date' has error: You must define callback via setEditableValueCallback(). ``` Viz: https://forum.nette.org/cs/13109-grido-datagrid-pro-nette?p=19#p164235 a https://forum.nette.org/cs/13109-grido-datagrid-pro-nette?p=19#p164380 --- src/Components/Columns/Editable.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Components/Columns/Editable.php b/src/Components/Columns/Editable.php index 74ee6302..16d8a61c 100644 --- a/src/Components/Columns/Editable.php +++ b/src/Components/Columns/Editable.php @@ -187,15 +187,28 @@ public function getHeaderPrototype() * Returns cell prototype ( html tag). * @param mixed $row * @return \Nette\Utils\Html + * @throws \Exception */ public function getCellPrototype($row = NULL) { $td = parent::getCellPrototype($row); if ($this->isEditable() && $row !== NULL) { - $td->data['grido-editable-value'] = $this->editableValueCallback === NULL + $editableValue = $this->editableValueCallback === NULL ? parent::getValue($row) : callback($this->editableValueCallback)->invokeArgs(array($row, $this)); + + if ((!is_array( $editableValue)) && + ((!is_object( $editableValue) && settype($editableValue, 'string') !== FALSE) || + (is_object($editableValue) && method_exists($editableValue, '__toString'))) + ) { + $td->data['grido-editable-value'] = $editableValue; + + } else { + $colName = $this->getColumn(); + $msg = "Column '$colName' has error: You must define callback via setEditableValueCallback()."; + throw new \Exception($msg); + } } return $td;