Repository: django-crispy-forms/django-crispy-forms

Issue:
Check boxes out of line - bootstrap4
Here's a photo of it. 
https://photos.app.goo.gl/upDVdprDouXJuVCq2


bootstrap 4 (bootstrap4)
django-crispy-forms - latest version installed today (-e git://github.com/maraujop/django-crispy-forms.git@dev#egg=django-crispy-forms)
django 1.11

here's my form
https://blib.me/signup/

Here's the related code from the forms.py:
```

    def __init__(self, *args, **kwargs):
        super(RegisterForm, self).__init__(*args, **kwargs)
        self.helper = FormHelper()
        self.helper.label_class = 'col-lg-6 col-md-8 col-sm-8'
        self.helper.field_class = 'col-lg-6 col-md-8 col-sm-8'
        self.helper.form_tag = False
        self.helper.layout = Layout(
            'categories',
            'allow_call',
            'allow_order',
            Field('name', autocomplete='organization'),
            Field('email', autocomplete='email'),
            Field('password', autocomplete='new-password'),
            Field('phone_number', autocomplete='tel'),
            Field('mobile_phone_number', autocomplete='tel'),
            'website',
            Field('street', autocomplete='address-line1'),
            Field('zipcode', autocomplete='postal-code'),
            Field('city', autocomplete='address-level2'),
            Field('country', autocomplete='country'),
            Field('language', autocomplete='language'),
            'timezone',
        )
```

and from models:
```

    allow_call = models.BooleanField(_("Allow custormers to call"), help_text=_("Show call button on your announcements."), default=True) 
    allow_order = models.BooleanField(_("Allow custormers to order"), help_text=_("Receive orders via our system. Show order button on your announcements."), default=True) 
```


Discussion:
anyone that can tell me if i did something wrong or if it's an issue, thanks
for some reason it seems like crispy forms have added the following class to the div that is wrapping the checkbox(es):
offset-lg-6 offset-md-8 offset-sm-8
Hi @michaelhjulskov. 

Can you look at #794. Is the issue described there for radios the same as you're seeing here for checkboxes? 
I'm closing the issue.
fixed it with this:
```
  <script type="text/javascript">
    $(document).ready(function() {
      $("div#div_id_allow_call").parent("div").css("margin-left", "initial");
    });
  </script>
```
Hi @carltongibson sorry I didnt see your comment. Iam not sure, but now I reported it and I am not sure if issue is caused by me or an issue.
I'll try and have a look. 
We're a bit stuck on the BS4 templates at the moment. We haven't got a maintainer who's actually using it. We're happy to include a fix for this issue and all the others if you (or someone) can step up. (Happy to provide guidance and that: it's just fixing the templates mostly...)

Resolving patch:
diff --git a/crispy_forms/helper.py b/crispy_forms/helper.py
--- a/crispy_forms/helper.py
+++ b/crispy_forms/helper.py
@@ -370,22 +370,17 @@ def get_attributes(self, template_pack=TEMPLATE_PACK):
             'field_class': self.field_class,
             'include_media': self.include_media
         }
-        
+
         if template_pack == 'bootstrap4':
-            bootstrap_size_match = re.findall(r'col-(xl|lg|md|sm)-(\d+)', self.label_class)
-            if bootstrap_size_match:
-                if template_pack == 'bootstrap4':
+            if 'form-horizontal' in self.form_class.split():
+                bootstrap_size_match = re.findall(r'col-(xl|lg|md|sm)-(\d+)', self.label_class)
+                if bootstrap_size_match:
                     offset_pattern = 'offset-%s-%s'
-                else:
-                    offset_pattern = 'col-%s-offset-%s'
-                items['bootstrap_checkbox_offsets'] = [offset_pattern % m for m in bootstrap_size_match]
+                    items['bootstrap_checkbox_offsets'] = [offset_pattern % m for m in bootstrap_size_match]
         else:
             bootstrap_size_match = re.findall(r'col-(lg|md|sm|xs)-(\d+)', self.label_class)
             if bootstrap_size_match:
-                if template_pack == 'bootstrap4':
-                    offset_pattern = 'offset-%s-%s'
-                else:
-                    offset_pattern = 'col-%s-offset-%s'
+                offset_pattern = 'col-%s-offset-%s'
                 items['bootstrap_checkbox_offsets'] = [offset_pattern % m for m in bootstrap_size_match]
 
         items['attrs'] = {}


Test patch:
diff --git a/crispy_forms/tests/test_form_helper.py b/crispy_forms/tests/test_form_helper.py
--- a/crispy_forms/tests/test_form_helper.py
+++ b/crispy_forms/tests/test_form_helper.py
@@ -810,14 +810,38 @@ def test_label_class_and_field_class_bs4():
     html = render_crispy_form(form)
 
     assert '<div class="form-group">' in html
-    assert '<div class="offset-lg-2 col-lg-8">' in html
+    assert '<div class="col-lg-8">' in html
     assert html.count('col-lg-8') == 7
+    assert 'offset' not in html
 
     form.helper.label_class = 'col-sm-3 col-md-4'
     form.helper.field_class = 'col-sm-8 col-md-6'
     html = render_crispy_form(form)
 
     assert '<div class="form-group">' in html
+    assert '<div class="col-sm-8 col-md-6">' in html
+    assert html.count('col-sm-8') == 7
+    assert 'offset' not in html
+
+
+@only_bootstrap4
+def test_label_class_and_field_class_bs4_offset_when_horizontal():
+    form = SampleForm()
+    form.helper = FormHelper()
+    form.helper.label_class = 'col-lg-2'
+    form.helper.field_class = 'col-lg-8'
+    form.helper.form_class = 'form-horizontal'
+    html = render_crispy_form(form)
+
+    assert '<div class="form-group row">' in html
+    assert '<div class="offset-lg-2 col-lg-8">' in html
+    assert html.count('col-lg-8') == 7
+
+    form.helper.label_class = 'col-sm-3 col-md-4'
+    form.helper.field_class = 'col-sm-8 col-md-6'
+    html = render_crispy_form(form)
+
+    assert '<div class="form-group row">' in html
     assert '<div class="offset-sm-3 offset-md-4 col-sm-8 col-md-6">' in html
     assert html.count('col-sm-8') == 7