Task #6004

Task #26664: Clean up Form ViewHelpers

Task #26658: Make Form ViewHelpers consistent

Checkbox viewHelper throws exception in "newAction" method.

Added by Nathan L over 5 years ago. Updated over 3 years ago.

Status:Closed Start date:2010-01-13
Priority:Should have Due date:
Assigned To:Bastian Waidelich % Done:

0%

Category:ViewHelpers
Target version:-
Has patch:No

Description

I'm not sure if this is a bug or just the way it is supposed to work. Maybe this should be filed under Fluid or not, I'm not sure. I made changes to my extBase model in order to make it work.

Here is an example scenario:

class Myobj {
/**
 * iampretty
 * @param boolean
 */
 protected $iampretty;

 // standard getter/setter
}

/**
 * Show a form to create a new object
 *
 * @param Tx_Myext_Domain_Model_Myobj $myobj A new object that is yet to be created
 * @return string A form for providing the objects properties.
 */
function newAction($myobj = NULL) {
    $this->view->assign('myobj',$myobj);
}

<f:form method="post" controller="Example" action="create"  name="myobj" object="{myobj}">

    <f:form.checkbox property="iampretty" value="1" /> Am I pretty?

<f:/form>

This throws an exception: #1243325768: No value found for key "Tx_Fluid_ViewHelpers_FormViewHelper->formObject"

However, if I modify my newAction to look like this, then the error isn't thrown:

function newAction($myobj = NULL) {
    if ($myobj == NULL) {
        $myobj = t3lib_div::makeInstance('Tx_Myext_Domain_Model_Myobj');
    }
    $this->view->assign('myobj',$myobj);
}

But there is a different issue! Here is how the checkbox renders:

Checkbox viewhelpers can only be bound to properties of type boolean or array. Property "iampretty" is of type "NULL".

I can make this go away by adding this constructor to my domain object:

public function __construct() {    
    $this->iampretty = false;
}

Now everything works! I'm just not sure if it this is how it is supposed to work.


Related issues

duplicates TYPO3.Fluid - Bug #8854: form.checkbox ViewHelper throws Exception in newAction Resolved 2010-07-14

History

#1 Updated by Christian Zenker over 4 years ago

I stumbled upon this behaviour recently.

#1243325768: No value found for key "Tx_Fluid_ViewHelpers_FormViewHelper->formObject"

I didn't know what this message was supposed to tell me, when I saw it the first time - and even now after reading the fix, I don't understand what it is supposed to mean. So at least the error message should be fixed.

To the second part (Checkbox viewhelpers can only be bound to properties of type boolean or array. Property "iampretty" is of type "NULL".):
I would not see this as a bug. When using the getter it will return NULL. The Form_CheckboxViewHelper could assume that NULL equals false, but I guess this is not the desired behaviour in some cases. Not knowing an answer to a question (=NULL) is just something different then saying "NO" (=false). So I'd say setting a default value is a perfectly clean solution. BTW a short-hand syntax for setting the value in the constructor would be


/**
 * @var boolean tells if you are pretty
 */
protected $iampretty = false;

#2 Updated by Sebastian Kurfuerst over 4 years ago

  • Project changed from Extbase MVC Framework to TYPO3.Fluid

#3 Updated by Sebastian Kurfuerst about 4 years ago

  • Parent task set to #26658

#4 Updated by Robert Lemke almost 4 years ago

  • Target version changed from 1.0 beta 2 to 1.0.0

#5 Updated by Karsten Dambekalns almost 4 years ago

  • Target version deleted (1.0.0)

#6 Updated by Bastian Waidelich over 3 years ago

  • Category set to ViewHelpers
  • Status changed from New to Closed
  • Assigned To set to Bastian Waidelich
  • Has patch set to No

Closing as duplicate of #8854

Also available in: Atom PDF