Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Symfony form formatter to use with Twitter Bootstrap v2.0 CSS
<?php
class sfWidgetFormSchemaFormatterBootstrap extends sfWidgetFormSchemaFormatter
{
protected
$rowFormat = "<div class=\"control-group %row_class%\">\n %label%\n <div class=\"controls\">\n %field%\n %error%\n %help%\n %hidden_fields%\n </div>\n</div>\n",
$errorRowFormat = '%errors%',
$errorListFormatInARow = "<span class=\"help-inline\">%errors%</span>\n",
$errorRowFormatInARow = "%error% ",
$namedErrorRowFormatInARow = "%name%: %error% ",
$helpFormat = '<p class="help-block">%help%</p>',
$decoratorFormat = '%content%';
public function formatRow($label, $field, $errors = array(), $help = '', $hiddenFields = null)
{
$row = parent::formatRow(
$label,
$field,
$errors,
$help,
$hiddenFields
);
return strtr($row, array(
'%row_class%' => count($errors) ? ' error' : '',
));
}
public function generateLabel($name, $attributes = array())
{
if(isset($attributes['class']))
{
$attributes['class'] .= ' control-label';
}
else
{
$attributes['class'] = 'control-label';
}
return parent::generateLabel($name, $attributes);
}
}
@aledujke

This comment has been minimized.

Copy link
Owner Author

@aledujke aledujke commented Mar 12, 2012

Some changes to make it work on twitter bootstrap 2.0 version.

@aledujke

This comment has been minimized.

Copy link
Owner Author

@aledujke aledujke commented Mar 20, 2012

Embedding forms seem to be broken when using this layout... not sure why. Will try to fix it.

@wikusv

This comment has been minimized.

Copy link

@wikusv wikusv commented Apr 18, 2012

Worked like a charm for me after adding $decoratorFormat = "%content%"; which stopped it from breaking embedded forms.

@aledujke

This comment has been minimized.

Copy link
Owner Author

@aledujke aledujke commented Apr 19, 2012

@wickass
wow thanks :) Haven't had the time to try it yet. This will hopefully help me tidy up my templates by a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment