Skip to content

Commit

Permalink
Make it possible to use SubmitField for LabelSubmit
Browse files Browse the repository at this point in the history
  • Loading branch information
johannaengland committed Oct 2, 2024
1 parent 63d4fd3 commit 0f25b87
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
8 changes: 7 additions & 1 deletion python/nav/web/crispyforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,17 +140,23 @@ class SubmitField:
:param name: The name attribute of the submit field.
:param value: The display text of the submit button.
:param css_classes: Additional CSS classes to apply to the submit button.
:param has_empty_label: If an empty label is added above the submit button to align it within a row.
:ivar input_type: The type of input, which is 'submit' for this class.
:type input_type: str
"""

def __init__(
self, name: str = 'submit', value: str = 'Submit', css_classes: str = ''
self,
name: str = 'submit',
value: str = 'Submit',
css_classes: str = '',
has_empty_label: bool = False,
):
"""Constructor method"""
self.name = name
self.value = value
self.css_classes = css_classes
self.has_empty_label = has_empty_label
self.input_type = 'submit'


Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{# NB! This field can be used as a replacement of crispy's Submit #}

{# NB! This field can be used as a replacement of crispy's Submit and our custom LabelSubmit #}
{% if input.has_empty_label %}
<label>&nbsp;</label>
{% endif %}
<input type="submit"
name="{% if input.name|wordcount > 1 %}{{ input.name|slugify }}{% else %}{{ input.name }}{% endif %}"
value="{{ input.value }}"
Expand Down

0 comments on commit 0f25b87

Please sign in to comment.