VA Forms Library - How to make a required form field optional
In some cases, you may want to make a form field fully optional, which requires updates to vets-json-schema, vets-website, and vets-api.
Making a required form field optional
Step 1: Update vets-json-schema
Open a PR in
vets-json-schema
Remove the field from the required property in your application’s specific schema. You’ll have to remove it twice; once from the schema JSON file, and once from the schema JavaScript file. (You’ll also increment the package.json version)
Important notes: If you're using a regex pattern to validate a field and you wish to make that field optional, you’ll need to adjust the regex in vets-json-schema
to accept an empty string or else the user won’t be able to advance without fulfilling the pattern required by the regex, even though the field won’t be marked as required.
Step 2: Update vets-website
Make your changes in
vets-website.
To test your changes locally, you can update your package.json and yarn.lock to point to the commit SHA of your
vets-json-schema
commit, and update the version referenced in the yarn.lock, and thenyarn install
.
Step 3: Update vets-api
Make a PR for
vets-api
that references the newvets-json-schema
version in thegemfile.lock
.
Tips and testing
You’ll want to try to merge your PRs as closely together as possible so that the schema version matches across backend and frontend. One tip is to merge after the production deploy for the day so you can have a longer period of time to test on Staging.
Testing notes
For making a field optional, you’ll want to remove it from any “minimal” tests in vets-website and the schema specs in vets-json-schema to make sure that the tests work without the field.
Help and feedback
Get help from the Platform Support Team in Slack.
Submit a feature idea to the Platform.