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 11 years ago. Updated over 9 years ago.

Status:
Closed
Priority:
Should have
Category:
ViewHelpers
Target version:
-
Start date:
2010-01-13
Due date:
% Done:

0%

Estimated time:
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

Is duplicate of TYPO3.Fluid - Bug #8854: form.checkbox ViewHelper throws Exception in newActionResolvedBastian Waidelich2010-07-14

Actions
#1

Updated by Christian Zenker almost 11 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 10 years ago

  • Project changed from 534 to TYPO3.Fluid
#3

Updated by Sebastian Kurfuerst over 10 years ago

  • Parent task set to #26658
#4

Updated by Robert Lemke about 10 years ago

  • Target version changed from 1.0 beta 2 to 1.0.0
#5

Updated by Karsten Dambekalns almost 10 years ago

  • Target version deleted (1.0.0)
#6

Updated by Bastian Waidelich over 9 years ago

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

Closing as duplicate of #8854

Also available in: Atom PDF