Skip to content

Commit

Permalink
Add "use div as legend" config and features value
Browse files Browse the repository at this point in the history
Let devs replace visible `legend` elems with `div`. Follows
accessibility guidelines by using `aria-labelledby` and `id`.

Devs can set "use div as legend" in the config file or the same key in
the features block to a boolean. The feature block value takes
precedence. This will change the visible HTML legend elements to divs.
If the dev uses anything other than a boolean, they get an error
message.

Why change only visible legend elements?

It is a smaller change that I thought would be more acceptable.

Why ensure always unique random ids?

Devs should not rely on the selector. Avoids later breaking changes.

Outcome of configuration combinations:

- [x] config: none/feature: none - legend
- [x] config: false/feature: none - legend
- [x] config: true/feature: none - div

- [x] config: none/feature: true - div
- [x] config: false/feature: true - div
- [x] config: true/feature: true - div

- [x] config: none/feature: false - legend
- [x] config: false/feature: false - legend
- [x] config: true/feature: false - legend

- [x] config: chair/feature: none - legend
- [x] config: chair/feature: true - div
- [x] config: chair/feature: false - legend

Error messages:

- [x] config: chair - websockets.log: The Configuration directive "use div as legend" must be True or False.
- [x] feature: chair - webpage: "use div as legend" in "features" must be either True or False.

Edited:

- docassemble_base/docassemble/base/config.py
- docassemble_base/docassemble/base/parse.py
- docassemble_base/docassemble/base/standardformatter.py
- docassemble_webapp/docassemble/webapp/static/app/app.css
- docassemble_webapp/docassemble/webapp/server.py
- tests/features/TestExamples.feature

Ignored:

- docassemble_demo/docassemble/demo/data/static/lumen.min.css:
    Disabling the styles in the DOM didn't have an effect.
- docassemble_webapp/docassemble/webapp/static/bootstrap/css/bootstrap.min.css:
    Same styles as lumen.
- docassemble_webapp/docassemble/webapp/static/app/cm6.js:
    Treats `div` and `legend` the same.
- docassemble_webapp/docassemble/webapp/static/app/jquery.min.js:
    jQuery uses `legend` in checks for disabled fields. Both `div`
    and `legend` cannot be disabled and from what I saw in the code
    I believe jQuery would treat them the same way:
    https://github.com/jquery/jquery/blob/03e183c4ccf22bf4031920c3270c9f113cb72d1d/src/selector.js#L277
    jQuery mentions the spec for disableable elements:
    https://github.com/jquery/jquery/blob/03e183c4ccf22bf4031920c3270c9f113cb72d1d/src/selector.js#L248-L250
- docassemble_webapp/docassemble/webapp/static/app/MaterialIcons-Regular.json:
    MaterialIcons icons are independent of the html that uses them.

Compiled files (ignored):

- docassemble_webapp/docassemble/webapp/static/app/adminbundle.js
- docassemble_webapp/docassemble/webapp/static/app/app.min.css
- docassemble_webapp/docassemble/webapp/static/app/bundle.css
- docassemble_webapp/docassemble/webapp/static/app/bundle.js
- docassemble_webapp/docassemble/webapp/static/app/cm6.min.js
- docassemble_webapp/docassemble/webapp/static/bootstrap/css/bootstrap.min.css.map

I found no a appearances of disabled associated with legends.

Co-authored-by: ttiimm <[email protected]>
  • Loading branch information
plocket and ttiimm committed Dec 1, 2024
1 parent 5332f40 commit d8ebfe5
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 29 deletions.
4 changes: 4 additions & 0 deletions docassemble_base/docassemble/base/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,10 @@ def load(**kwargs):
daconfig['web server'] = 'nginx'
if 'table css class' not in daconfig or not isinstance(daconfig['table css class'], str):
daconfig['table css class'] = 'table table-striped'
if 'use div as legend' in daconfig:
if not isinstance(daconfig['use div as legend'], bool):
config_error('The Configuration directive "use div as legend" must be True or False.')
del daconfig['use div as legend']
if env_true_false('ENVIRONMENT_TAKES_PRECEDENCE'):
messages = []
for env_var, key in (('DBPREFIX', 'prefix'), ('DBNAME', 'name'), ('DBUSER', 'user'), ('DBPASSWORD', 'password'), ('DBHOST', 'host'), ('DBPORT', 'port'), ('DBTABLEPREFIX', 'table prefix'), ('DBBACKUP', 'backup'), ('DBSSLMODE', 'ssl mode'), ('DBSSLCERT', 'ssl cert'), ('DBSSLKEY', 'ssl key'), ('DBSSLROOTCERT', 'ssl root cert')):
Expand Down
4 changes: 4 additions & 0 deletions docassemble_base/docassemble/base/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -2260,6 +2260,10 @@ def __init__(self, orig_data, caller, **kwargs):
self.interview.options['hide standard menu'] = data['features']['hide standard menu']
if 'labels above fields' in data['features'] and isinstance(data['features']['labels above fields'], bool):
self.interview.options['labels above'] = data['features']['labels above fields']
if 'use div as legend' in data['features']:
if not isinstance(data['features']['use div as legend'], bool):
raise DASourceError('"use div as legend" in the "features" block must be either True or False.' + self.idebug(data))
self.interview.options['use div as legend'] = data['features']['use div as legend']
if 'suppress autofill' in data['features'] and isinstance(data['features']['suppress autofill'], bool):
self.interview.options['suppress autofill'] = data['features']['suppress autofill']
if 'floating labels' in data['features'] and isinstance(data['features']['floating labels'], bool):
Expand Down
Loading

0 comments on commit d8ebfe5

Please sign in to comment.