Skip to content

Commit

Permalink
Merge pull request sonata-project#1027 from TomAdam/pr-form-group-des…
Browse files Browse the repository at this point in the history
…cription

Add form group description
  • Loading branch information
rande committed Nov 20, 2012
2 parents db6ba5b + 5302d91 commit d8951b5
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 15 deletions.
6 changes: 3 additions & 3 deletions Form/FormMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

use Sonata\AdminBundle\Builder\FormContractorInterface;
use Sonata\AdminBundle\Admin\AdminInterface;
use Sonata\AdminBundle\Admin\FieldDescriptionInterface;
use Symfony\Component\Form\FormBuilder;

/**
Expand Down Expand Up @@ -55,8 +54,9 @@ public function with($name, array $options = array())
}

$formGroups[$name] = array_merge(array(
'collapsed' => false,
'fields' => array()
'collapsed' => false,
'fields' => array(),
'description' => false
), $formGroups[$name], $options);

$this->admin->setFormGroups($formGroups);
Expand Down
32 changes: 27 additions & 5 deletions Resources/doc/reference/form_help_message.rst
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
Form Help Messages
==================
Form Help Messages and Descriptions
===================================

Help Messages
-------------

Help messages are short notes that are rendered together with form fields. They are generally used to show additional information so the user can complete the form element faster and more accurately.
Help messages are short notes that are rendered together with form fields. They are generally used to show additional information so the user can complete the form element faster and more accurately. The text is not escaped, so HTML can be used.

Example
-------
^^^^^^^

.. code-block:: php
Expand All @@ -25,7 +25,7 @@ Example
}
Alternative Way To Define Help Messages
---------------------------------------
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code-block:: php
Expand All @@ -46,3 +46,25 @@ Alternative Way To Define Help Messages
}
}
Form Group Descriptions
-----------------------

A form group description is a block of text rendered below the group title. These can be used to describe a section of a form. The text is not escaped, so HTML can be used.

Example
^^^^^^^

.. code-block:: php
<?php
class ExampleAdmin.php
{
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->with('General', array('description' => 'This section contains general settings for the web page'))
->add('title', null, array('help'=>'Set the title of a web page'))
->add('keywords', null, array('help'=>'Set the keywords of a web page'))
->end();
}
}
4 changes: 2 additions & 2 deletions Resources/public/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ var Admin = {
* @param subject
*/
add_collapsed_toggle: function(subject) {
jQuery('fieldset.sonata-ba-fielset-collapsed').has('.error').addClass('sonata-ba-collapsed-fields-close');
jQuery('fieldset.sonata-ba-fielset-collapsed div.sonata-ba-collapsed-fields').not(':has(.error)').hide();
jQuery('fieldset.sonata-ba-fieldset-collapsed').has('.error').addClass('sonata-ba-collapsed-fields-close');
jQuery('fieldset.sonata-ba-fieldset-collapsed div.sonata-ba-collapsed-fields').not(':has(.error)').hide();
jQuery('fieldset legend a.sonata-ba-collapsed', subject).live('click', function(event) {
event.preventDefault();

Expand Down
12 changes: 10 additions & 2 deletions Resources/public/css/layout.css
Original file line number Diff line number Diff line change
Expand Up @@ -278,11 +278,19 @@ legend + .sonata-ba-collapsed-fields {
-webkit-margin-top-collapse: separate;
}

legend.sonata-ba-fieldset-collapsed-description + .sonata-ba-collapsed-fields {
margin-top: 0;
}

.sonata-ba-collapsed-fields > p {
margin-bottom: 18px;
}

.bordered-table tbody.ui-sortable tr {
cursor: move;
}

.sonata-ba-fielset-collapsed legend:before {
.sonata-ba-fieldset-collapsed legend:before {
content: '+ ';
}

Expand All @@ -297,4 +305,4 @@ legend + .sonata-ba-collapsed-fields {

.sonata-bc .pagination {
margin: 0px;
}
}
10 changes: 7 additions & 3 deletions Resources/views/CRUD/base_edit_form.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
{% block sonata_pre_fieldsets %}{% endblock %}

{% for name, form_group in admin.formgroups %}
<fieldset {% if form_group.collapsed %}class="sonata-ba-fielset-collapsed"{% endif %}>
<legend>
<fieldset {% if form_group.collapsed %}class="sonata-ba-fieldset-collapsed"{% endif %}>
<legend{% if form_group.description != false %} class="sonata-ba-fieldset-collapsed-description"{% endif %}>
{% if form_group.collapsed %}
<a href="" class="sonata-ba-collapsed" title="{{ 'link_expand'|trans({}, 'SonataAdminBundle') }}">{{ name|trans({}, admin.translationdomain) }}</a>
{% else %}
Expand All @@ -26,6 +26,10 @@
</legend>

<div class="sonata-ba-collapsed-fields">
{% if form_group.description != false %}
<p>{{ form_group.description|raw }}</p>
{% endif %}

{% for field_name in form_group.fields %}
{% if admin.formfielddescriptions[field_name] is defined %}
{{ form_row(form[field_name])}}
Expand Down Expand Up @@ -70,4 +74,4 @@
</form>
{% endif%}

{% endblock %}
{% endblock %}

0 comments on commit d8951b5

Please sign in to comment.