Add date input day, month, year and values options#6971
Open
colinrotherham wants to merge 7 commits into
Open
Conversation
Contributor
|
Hi @colinrotherham. This is looking great! Thanks for reimplementing this. At the moment we're keen to keep I'll run this past the other devs but if they're happy with this solution we can reivew this and put it on hold until we're ready to merge it. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR contributes some date input changes from NHS.UK frontend to add new Nunjucks options:
day,monthandyearto customise individual itemsvaluesoption to set item values using a single objectIt closes #1154 and is based on: nhsuk/nhsuk-frontend#1869
Apologies to @joelanman as this PR re-implements #4932 without any breaking changes
Setting individual values and errors
Rather than set every
itemsobject (for day, month and year) we can now partially override the defaultsFor example, setting
error: trueon the year item no longer requires all other item defaults to be set:{{ govukDateInput({ fieldset: { legend: { text: "What is your date of birth?" } }, - items: [ - { - name: "dob-day", - label: "Day", - classes: "govuk-input--width-2" - }, - { - name: "dob-month", - label: "Month", - classes: "govuk-input--width-2" - }, - { - name: "dob-year", - label: "Year", - classes: "govuk-input--width-4", - error: true - } - ] + namePrefix: "dob", + year: { + error: true + } }) }}Setting all values at once
Or when using the GOV.UK Prototype Kit, given the following
dataobject:{ "dob-day": "31", "dob-month": "3", "dob-year": "1980" }You can now automatically set item values by passing in
values: dataas shown: