Skip to content

Commit

Permalink
Merge pull request #33753 from dimagi/bmb/form-field-action-css-templ…
Browse files Browse the repository at this point in the history
…ate-tags-b5

[B5] update field, label, and action class template tags to be compatible with bootstrap 5
  • Loading branch information
biyeun authored Nov 22, 2023
2 parents 9badfba + 942b646 commit 152ba6b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
5 changes: 5 additions & 0 deletions corehq/apps/hqwebapp/crispy.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ class ErrorsOnlyField(Field):
template = 'hqwebapp/crispy/field/errors_only_field.html'


def get_form_action_class():
"""This is only valid for bootstrap 5"""
return CSS_LABEL_CLASS_BOOTSTRAP5.replace('col', 'offset') + ' ' + CSS_FIELD_CLASS_BOOTSTRAP5


def _get_offsets(context):
label_class = context.get('label_class', '')
use_bootstrap5 = context.get('use_bootstrap5')
Expand Down
15 changes: 12 additions & 3 deletions corehq/apps/hqwebapp/templatetags/hq_shared_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,19 +237,28 @@ def can_use_restore_as(request):

@register.simple_tag
def css_label_class():
from corehq.apps.hqwebapp.crispy import CSS_LABEL_CLASS
from corehq.apps.hqwebapp.crispy import CSS_LABEL_CLASS, CSS_LABEL_CLASS_BOOTSTRAP5
from corehq.apps.hqwebapp.utils.bootstrap import get_bootstrap_version, BOOTSTRAP_5
if get_bootstrap_version() == BOOTSTRAP_5:
return CSS_LABEL_CLASS_BOOTSTRAP5
return CSS_LABEL_CLASS


@register.simple_tag
def css_field_class():
from corehq.apps.hqwebapp.crispy import CSS_FIELD_CLASS
from corehq.apps.hqwebapp.crispy import CSS_FIELD_CLASS, CSS_FIELD_CLASS_BOOTSTRAP5
from corehq.apps.hqwebapp.utils.bootstrap import get_bootstrap_version, BOOTSTRAP_5
if get_bootstrap_version() == BOOTSTRAP_5:
return CSS_FIELD_CLASS_BOOTSTRAP5
return CSS_FIELD_CLASS


@register.simple_tag
def css_action_class():
from corehq.apps.hqwebapp.crispy import CSS_ACTION_CLASS
from corehq.apps.hqwebapp.crispy import CSS_ACTION_CLASS, get_form_action_class
from corehq.apps.hqwebapp.utils.bootstrap import get_bootstrap_version, BOOTSTRAP_5
if get_bootstrap_version() == BOOTSTRAP_5:
return get_form_action_class()
return CSS_ACTION_CLASS


Expand Down

0 comments on commit 152ba6b

Please sign in to comment.