-
Notifications
You must be signed in to change notification settings - Fork 334
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow attributes on date input items #995
Comments
Hi @malcolmhire , One possible solution would be to move the I have also created a ticket in our backlog so we can track this. |
I wonder if objects could be merged using a for loop |
When you say 'directly to the component' do you mean adding it directly to the govukInput? I thought about adding it like that with the pattern as part of the govukInput, this would then leave open attributes object, but this wouldn't be consistent with all the other components so ditched that idea. @igloosi is this the sort of thing you were meaning?
|
@malcolmhire something along those lines yes, but you're right, it lacks consistency
perhaps we might have to allow an array of objects to be passed as attributes @malcolmhire
so attributes is passed as an array of objects we could loop over them and merge them with the default attributes Nunjucks array loop
Nunjucks object loop
your thoughts? |
Hey, sorry for the late reply, been on leave. I think that idea will work but again is it not consistent with the other components as attributes are a single object on all other components (unless I've missed something). Thoughts? |
@malcolmhire yeah they are. I also did some quick testing and there isn't a reliable way to check with |
I've spoken with Hanna about this, and we think these are the ways forward: 1. Go with current proposal that overrides attributes, and make guidance (YAML) clearer that the pattern attributes need to be added again manually.Risks:
2. Investigate if it's possible to add a global function for merging without making immediate breaking changes.Risks:
3. Investigate a private attributes API on the input component that is only used when composing the component like in date input.
We'd need to ensure that the additional attributes overrides existing attributes before they're applied. Risks:
4. Consider adding 'pattern' as a top level API for text input, avoiding the need to merge attributes.Risks:
|
I've gone over this with @36degrees and had a separate discussion with @hannalaakso. We think there are risks with option 1. which I've updated in the previous comment, and that we should go with an alternative that avoids this. So we are proposing to add Which will allow the user to set attributes without having to remove the defaults. The reasoning for this is we think that the We would then do a technical spike into option 2. as we think that being able to use global functions has enough evidence of usefulness but we don't want to block this until we've figured that out. @colinrotherham @malcolmhire how does that sound? |
Yeah sounds good to me. Just like the work to enable Also if absolutely required we can still add {{ govukDateInput({
items: [
{
// If omitted, default is still set
pattern: "[0-9]*",
// Additional attributes
attributes: {
min: "1",
max: "31"
}
}
]
}) }} |
@colinrotherham yes, we'll still keep the attributes for users of the macro to add their additional attributes 👍 |
Perfect. This is now supported by #1172 |
This looks good to me 😀 |
Can this be closed now or shall we keep it open for the further Nunjucks object merging changes? |
Currently, there is no way of adding extra attributes to each of the date input fields, this would be a fairly easy update but the macro already sets attributes on Line 67 and as there no built in way to merge objects in Nunjucks (well not that I know of) this would require a filter, but this would need to added application side when initializing Nunjucks.
Any ideas how to achieve this?
The text was updated successfully, but these errors were encountered: