浏览代码

Merge pull request #3672 from vincenttouzet/master

Fix #2630 : "Delete" label rendering on embedded collection + add space between checkbox and label when using icheck
Oskar Stark 9 年之前
父节点
当前提交
0dea877501

+ 44 - 0
Resources/public/css/styles.css

@@ -351,6 +351,50 @@ td.sonata-ba-list-field .editable-empty:not(.editable-open) {
     width: auto; /* See https://github.com/sonata-project/SonataAdminBundle/issues/2950 */
 }
 
+/**
+ * Make checkbox / radio label consistant with other labels
+ */
+.checkbox label,
+.radio label {
+    font-weight: 700;
+}
+
+/**
+ * The iCheck checkboxes & radios have 0 margin by default,
+ * add some space for the label text.
+ */
+.checkbox div[class^="icheckbox"],
+.checkbox-inline div[class^="icheckbox"],
+.radio div[class^="iradio"],
+.radio-inline div[class^="iradio"] {
+    position: relative;
+    margin-top: 4px \9;
+    margin-left: -20px;
+    margin-right: 5px;
+    margin-top: -3px;
+}
+.form-inline .checkbox div[class^="icheckbox"],
+.form-inline .checkbox-inline div[class^="icheckbox"],
+.form-inline .radio div[class^="iradio"],
+.form-inline .radio-inline div[class^="iradio"] {
+    position: relative;
+    margin-top: 4px \9;
+    margin-left: 0;
+    margin-right: 5px;
+    margin-top: -3px;
+}
+/* Hide Delete checkbox on sonata_type_collection tables */
+.sonata-ba-field-inline-table td > div.checkbox > label > .control-label__text {
+    position: absolute;
+    width: 1px;
+    height: 1px;
+    padding: 0;
+    margin: -1px;
+    overflow: hidden;
+    clip: rect(0,0,0,0);
+    border: 0;
+}
+
 /* select2 */
 .select2-choice, .select2-choices, .select2-drop {
     border-radius: 0 !important;

+ 7 - 3
Resources/views/Form/form_admin_fields.html.twig

@@ -80,7 +80,7 @@ file that was distributed with this source code.
 
 {% block checkbox_widget -%}
     {% set parent_label_class = parent_label_class|default('') -%}
-    {% if 'checkbox-inline' in parent_label_class or sonata_admin.options['use_icheck'] %}
+    {% if 'checkbox-inline' in parent_label_class %}
         {{- form_label(form, null, { widget: parent() }) -}}
     {% else -%}
         <div class="checkbox">
@@ -91,7 +91,7 @@ file that was distributed with this source code.
 
 {% block radio_widget -%}
     {%- set parent_label_class = parent_label_class|default('') -%}
-    {% if 'radio-inline' in parent_label_class or sonata_admin.options['use_icheck'] %}
+    {% if 'radio-inline' in parent_label_class %}
         {{- form_label(form, null, { widget: parent() }) -}}
     {% else -%}
         <div class="radio">
@@ -166,7 +166,11 @@ file that was distributed with this source code.
         {% endif %}
         <label{% for attrname, attrvalue in label_attr %} {{ attrname }}="{{ attrvalue }}"{% endfor %}>
             {{- widget|raw -}}
-            {{- label is not same as(false) ? label|trans({}, translation_domain) -}}
+            {%- if label is not same as(false) -%}
+                <span class="control-label__text">
+                    {{- label|trans({}, translation_domain) -}}
+                </span>
+            {%- endif -%}
         </label>
     {% endif %}
 {% endblock checkbox_radio_label %}

+ 1 - 29
Tests/Form/Widget/FormChoiceWidgetTest.php

@@ -39,35 +39,7 @@ class FormChoiceWidgetTest extends BaseWidgetTest
         $html = $this->renderWidget($choice->createView());
 
         $this->assertContains(
-            '<li><label><input type="checkbox" id="choice_0" name="choice[]" value="0" />[trans]some[/trans]</label></li>',
-            $this->cleanHtmlWhitespace($html)
-        );
-    }
-
-    public function testBootstrapLabelRendering()
-    {
-        $sonataAdmin = $this->getSonataAdmin();
-        $sonataAdmin['options']['use_icheck'] = false;
-        $this->environment->addGlobal('sonata_admin', $sonataAdmin);
-
-        $choices = array('some', 'choices');
-        if (!method_exists('Symfony\Component\Form\FormTypeInterface', 'setDefaultOptions')) {
-            $choices = array_flip($choices);
-        }
-
-        $choice = $this->factory->create(
-            $this->getChoiceClass(),
-            null,
-            $this->getDefaultOption() + array(
-                'multiple' => true,
-                'expanded' => true,
-            ) + compact('choices')
-        );
-
-        $html = $this->renderWidget($choice->createView());
-
-        $this->assertContains(
-            '<li><div class="checkbox"><label><input type="checkbox" id="choice_0" name="choice[]" value="0" />[trans]some[/trans]</label></div></li>',
+            '<li><div class="checkbox"><label><input type="checkbox" id="choice_0" name="choice[]" value="0" /><span class="control-label__text">[trans]some[/trans]</span></label></div></li>',
             $this->cleanHtmlWhitespace($html)
         );
     }