Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does not work with Form_Subform - solution provided #13

Open
doramoldovan opened this issue May 15, 2012 · 3 comments
Open

Does not work with Form_Subform - solution provided #13

doramoldovan opened this issue May 15, 2012 · 3 comments

Comments

@doramoldovan
Copy link

Hi,

Thanks for the lovely and painlessly way of implementing this.
However while switching to Twitter_Form, i noticed the subforms were still styled by Zend, so i added the simple Twitter_Form_SubForm class to handle that.
Code below:

loadDefaultDecoratorsIsDisabled()) { return $this; } $decorators = null; if (empty($decorators)) { $this->addDecorator('FormElements') ->addDecorator("Label", array("class" => "control-label")) ->addDecorator(array("innerwrapper" => "HtmlTag"), array("tag" => "div", "class" => "controls")) ->addDecorator("Description", array("tag" => "span", "class" => "help-block")) ->addDecorator('Errors', array("placement" => "append")) ->addDecorator(array("outerwrapper" => "HtmlTag"), array("tag" => "div", "class" => "control-group")); } return $this; } ``` } ?>
@pebbo
Copy link

pebbo commented Jun 7, 2012

Tried a similar solution but mine (and yours) just throw me warnings... is it working for you?
When I temporary add the methods "getLabel()" and "isRequired()" I get my code to work but there are many forms rendered within each other then :( cannot imagine that this works for you!?

@doramoldovan
Copy link
Author

Hi,

We have this implemented on a live site and it's working fine. Can you share more of your specifics for your implementation?

Thanks,
Dora

@Spodnet
Copy link

Spodnet commented Jan 9, 2013

Possibly a bit late, I was also having the issue of multiple form tags with this code and sub forms.

I made the following alterations to the render call in Twitter_Form, I added an if around the for loop checking if the form was an instanceof Twitter_Form_SubForm, this removed the extra form tags, but the actions were set in the middle of the form before the sub forms. So at the end I set the order of those actions to 99999, ie a large number to push them to the end. This appears to be working ok for me.

I add the sub forms dynamically which maybe why the actions are in the middle of my form, so may not apply to everyone.

/**
 * Render
 * @param  Zend_View_Interface $view
 * @return Zend_View
 */
public function render(Zend_View_Interface $view = null)
{
    $formTypes = array( // avaible form types of Twitter Bootstrap form (i.e. classes)
      'horizontal',
      'inline',
      'vertical',
      'search'
    );

    $set = false;

    // don't add to sub forms
    if (!($this instanceof Twitter_Form_SubForm)) {
        foreach($formTypes as $type) {
            if($this->getAttrib($type)) {
                $this->addDecorator("Form", array("class" => "form-$type"));
                $set = true;
            }
        }

        if(true !== $set) { // if neither type was set, we set the default vertical class
            $this->addDecorator("Form", array("class" => "form-vertical"));
        }
    }

    // finally move the zfBootstrapFormActions display group to the end
    $displayGroup = $this->getDisplayGroup("zfBootstrapFormActions");
    $displayGroup->setOrder(99999);

    return parent::render($view);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants