Created
November 26, 2021 16:58
-
-
Save peteryates/c15f5018b527cf3af92cb121e048d117 to your computer and use it in GitHub Desktop.
suggested simplification
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/govuk_design_system_formbuilder/elements/date.rb b/lib/govuk_design_system_formbuilder/elements/date.rb | |
index 84430d1..b11bc4e 100644 | |
--- a/lib/govuk_design_system_formbuilder/elements/date.rb | |
+++ b/lib/govuk_design_system_formbuilder/elements/date.rb | |
@@ -56,33 +56,21 @@ module GOVUKDesignSystemFormBuilder | |
def day | |
return if omit_day? | |
- if maxlength_enabled? | |
- date_part(:day, width: 2, link_errors: true, maxlength: 2) | |
- else | |
- date_part(:day, width: 2, link_errors: true) | |
- end | |
+ date_part(:day, width: 2, link_errors: true) | |
end | |
def month | |
- if maxlength_enabled? | |
- date_part(:month, width: 2, link_errors: omit_day?, maxlength: 2) | |
- else | |
- date_part(:month, width: 2, link_errors: omit_day?) | |
- end | |
+ date_part(:month, width: 2, link_errors: omit_day?) | |
end | |
def year | |
- if maxlength_enabled? | |
- date_part(:year, width: 4, maxlength: 4) | |
- else | |
- date_part(:year, width: 4) | |
- end | |
+ date_part(:year, width: 4) | |
end | |
- def date_part(segment, width:, link_errors: false, maxlength: nil) | |
+ def date_part(segment, width:, link_errors: false) | |
tag.div(class: %(#{brand}-date-input__item)) do | |
tag.div(class: %(#{brand}-form-group)) do | |
- safe_join([label(segment, link_errors), input(segment, link_errors, width, value(segment), maxlength)]) | |
+ safe_join([label(segment, link_errors), input(segment, link_errors, width, value(segment))]) | |
end | |
end | |
end | |
@@ -113,7 +101,7 @@ module GOVUKDesignSystemFormBuilder | |
) | |
end | |
- def input(segment, link_errors, width, value, maxlength) | |
+ def input(segment, link_errors, width, value) | |
tag.input( | |
id: id(segment, link_errors), | |
class: classes(width), | |
@@ -123,7 +111,7 @@ module GOVUKDesignSystemFormBuilder | |
inputmode: 'numeric', | |
value: value, | |
autocomplete: date_of_birth_autocomplete_value(segment), | |
- maxlength: maxlength, | |
+ maxlength: (width if maxlength_enabled?) | |
) | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment