This repository has been archived by the owner on Nov 27, 2020. It is now read-only.
generated from cds-snc/.github
-
Notifications
You must be signed in to change notification settings - Fork 3
Conversation
This file contains 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
TLDR; For the future: Given a form schemas we don't have a quick way of saying whether a field is required or not i.e. is required true or false We have checks such as
As far as making the data available we can make things like res locals available to the macros which in turn could look up a required field. Sample code: // app.js
app.set('view engine', 'njk')
app.set('engine', env) const routeMiddleware = (route, locale) => (req, res, next) => {
// ...more code
const engine = res.app.get('engine')
engine.addGlobal('locals', res.locals)
return next()
} {% macro textInput(name, label, attributes) %}
...
<code>{{ locals.route.name}} !!!</code
// do the lookup based on the field name + making the schema available here See: https://blog.eexit.net/nunjucks-inject-express-request/ Thinking we would write some functions to handle i.e. isRequiredField. That said the scope stretches quite a bit beyond what I think we need in this PR. Needs some further thinking. |
maxneuvians
approved these changes
Oct 23, 2019
Closed
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Adds * and (required) to field labels when you pass
As an attribute to the macro.
#98
Note: Ideally I would like to hook this to the form schema i.e. one place to set required on the fields
@JuliannaR if you can take a look at this that would be great.
Example: