-
Notifications
You must be signed in to change notification settings - Fork 7
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
date macro pattern #397
date macro pattern #397
Conversation
@@ -11,6 +11,7 @@ | |||
|
|||
{% from "_macros/form.njk" import EntitySearchForm, Form, MultiStepForm with context %} | |||
{% from "_macros/form.njk" import Fieldset, TextField, MultipleChoiceField, HiddenField %} | |||
{% from "_macros/form.njk" import DateField %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could extend the line above instead:
{% from "_macros/form.njk" import Fieldset, DateField, TextField, MultipleChoiceField, HiddenField %}
src/templates/_macros/form.njk
Outdated
@@ -351,6 +358,7 @@ | |||
# @param {string} [props.placeholder] - Field placeholder | |||
# @param {string, array} [props.modifier] - form-control modifier | |||
# @param {string} [props.error] - Mark form-control with error | |||
# @param {string} [props.maxlength] - maxlength Input attribute |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maxlength can be confusing to users. Could be better just to validate whatever the user enters rather than restricting input?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would be interesting to see what the preferred users options is. I wonder if entering something long, which disappears from view to then be told its not valid is preferred to restricting the characters entered
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
which disappears from view
It doesn't disappear on most browsers. The cursor will follow the last typed characters so even on smaller input fields the user will still see what they last typed. It would actually seem more like it disappears in this instance if we restrict input.
restricting the characters entered
Some users don't look at the screen when they're typing so they won't necessarily notice that everything they typed on the keyboard isn't on the screen, which is where the confusion often comes from.
This is particularly noticeable in free text fields where the accepted characters are limited. It is better to let the user type over that limit and warn them as they do so as well as validate when they submit or prevent them from submitting.
Twitter's tweet functionality is a good example - it doesn't just stop you writing, it shows you that you typed too much:
In this instance with date fields I don't think restricting input adds anything and we're better off just letting the user enter as many characters as they want to and then providing useful date validation feedback if it isn't a valid date.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great point - well made 👍
src/templates/_macros/form.njk
Outdated
# @param {string} [props.inputName] - The base input name for date field names | ||
# @param {string} [props.inputValue] - Field values | ||
#} | ||
{% macro DateField(props) %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DateFieldset
?
max-width: 4em; | ||
} | ||
|
||
.c-form-control--small { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be worth looking at @tyom's suggestion from the other PR again.
cccce13
to
128dbaa
Compare
128dbaa
to
3167d28
Compare
Might be worth adding some examples of the date fieldset to the examples in components app too. |
👍 yeah this and tests are in the TODO's on #395 |
# @param {string} [props.inputName] - The base input name for date field names | ||
# @param {string} [props.inputValue] - Field values | ||
#} | ||
{% macro DateFieldset(props) %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I try to add unit tests for all new macros. I know there' a backlog but do consider adding some tests if you can.
6e6a494
to
3b0248c
Compare
src/templates/_macros/form.njk
Outdated
> | ||
{% if props.legend %} | ||
<legend class="c-form-fieldset__legend"> | ||
<span class="c-form-fieldset__legend-text">{{ props.legend }}</span> | ||
</legend> | ||
{% endif %} | ||
|
||
{% if props.hint %} | ||
<span id="hint-{{ props.fieldId }}" class="c-form-fieldset__hint">{{ props.hint }}</span> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might as well use div
. I doubt it would ever be displayed inline.
src/templates/_macros/form.njk
Outdated
|
||
{% call FormGroup(props | assign({ fieldId: fieldId, element: 'fieldset', modifier: 'inline' })) %} | ||
{{ TextField({ | ||
inputClass: 'c-form-control--shortest', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can just add this to modifier modifier: ['inline', 'shortest']
.
Would be good to add example of this fieldset to form components page. |
closing this as the work can be found in #395 |
an error with missing stles - full PR can be seen on #395 |
All comments addressed in #395 |
Usage can be seen in #395 here