Skip to content

Commit

Permalink
use divs and aria instead of fieldset and legend, due to Safari bug; …
Browse files Browse the repository at this point in the history
…added raise_undefined_attribute_error method of DAObject; added raise_undefined_index_error method of DAList and DADict; removed the docassemble namespace package, which is not necessary
  • Loading branch information
jhpyle committed Dec 7, 2024
1 parent ed8258a commit 84fb269
Show file tree
Hide file tree
Showing 23 changed files with 149 additions and 43 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change Log

## [1.6.1] - 2024-12-07

### Fixed
- Rendering issue with radio buttons and checkboxes on Safari.

## [1.6.0] - 2024-11-30

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ subquestion: |
Your favorite vegetable is ${ favorite_vegetable }.
% if not defined('favorite_vegetable_placeholder'):
Note that the variable
`favorite_vegetable_placeholder` is not defined.
% endif
mandatory: True
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ question: Result of question
subquestion: |
Your favorite fruit is ${ favorite_fruit }.
% if not defined('favorite_vegetable'):
The `favorite_vegetable` variable
was not defined by the previous
question because the field was
disabled.
% endif
mandatory: True
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ fields:
question: |
What is your favorite vegetable?
fields:
- Favorite fruit: favorite_vegetable
- Favorite vegetable: favorite_vegetable
---
table:
fruit_list.table
Expand Down
25 changes: 19 additions & 6 deletions docassemble_base/docassemble/base/standardformatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,25 +568,32 @@ def help_wrap(content, helptext, status):

def field_item(field, grid_info, pre=None, row=True, floating=False, classes=None, hidden_message=None, label_for=None, label_classes=None, label_content=None, grid_type=None, content_classes=None, content=None, side_note=None, under_text=None, use_fieldset=0, required=False):
if use_fieldset:
enclosing_type = 'fieldset'
label_type = 'legend'
enclosing_type = 'div'
label_type = 'div'
if required:
aria_req = 'aria-required="true" '
else:
aria_req = ''
if use_fieldset == 1:
aria_req += 'role="radiogroup" '
id_for_label = f'da-label-{field.number}'
aria_lb = f' aria-labeledby="{id_for_label}" '
label_id = f' id="{id_for_label}"'
else:
enclosing_type = 'div'
label_type = 'label'
aria_req = ''
aria_lb = ' '
label_id = ''
if grid_info['_enabled']:
grid_number = grid_info[field.number]['grid']
else:
grid_number = None
if grid_number:
if label_content is not None:
all_label_classes = []
if use_fieldset:
all_label_classes.append('da-legend')
if grid_type == 'horizontal':
label_width_number = grid_info[field.number].get('label width', None) or daconfig['grid classes']['label grid number']
label_width = 100.0 * (label_width_number/(label_width_number + grid_number))
Expand All @@ -596,7 +603,7 @@ def field_item(field, grid_info, pre=None, row=True, floating=False, classes=Non
label_style = ''
if label_classes:
all_label_classes.append(label_classes)
label_text = '\n <' + label_type + label_style
label_text = '\n <' + label_type + label_id + label_style
if label_for:
label_text += label_for
if len(all_label_classes) > 0:
Expand All @@ -611,10 +618,12 @@ def field_item(field, grid_info, pre=None, row=True, floating=False, classes=Non
label_text = None
grid_label_above = label_text and not floating and not row and grid_type is None
# update_parent_classes(fieldlist, grid_info[field.number]['index'], classes)
output = ' <' + enclosing_type + ' ' + aria_req
output = ' <' + enclosing_type + aria_lb + aria_req
if pre:
output += pre
all_classes = ['da-grid-container']
if use_fieldset:
all_classes.append('da-fieldset')
all_content_classes = []
content_styles = {}
if 'breakpoint' in grid_info[field.number]:
Expand Down Expand Up @@ -695,11 +704,13 @@ def field_item(field, grid_info, pre=None, row=True, floating=False, classes=Non
else:
if label_content:
all_label_classes = []
if use_fieldset:
all_label_classes.append('da-legend')
if grid_type == 'horizontal':
all_label_classes.append('col-' + daconfig['grid classes']['label width'] + ' col-form-label da-form-label datext-right')
if label_classes:
all_label_classes.append(label_classes)
label_text = '\n <' + label_type
label_text = '\n <' + label_type + label_id
if label_for:
label_text += label_for
if len(all_label_classes) > 0:
Expand All @@ -712,10 +723,12 @@ def field_item(field, grid_info, pre=None, row=True, floating=False, classes=Non
label_text = '<legend class="visually-hidden">' + str(hidden_message) + '</legend>'
else:
label_text = None
output = ' <' + enclosing_type + ' ' + aria_req
output = ' <' + enclosing_type + aria_lb + aria_req
if pre:
output += pre
all_classes = ['da-container']
if use_fieldset:
all_classes.append('da-fieldset')
if not floating:
all_classes.append('da-form-group')
if row:
Expand Down
13 changes: 13 additions & 0 deletions docassemble_base/docassemble/base/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,11 @@ def __getattr__(self, thename):
docassemble.base.functions.this_thread.misc['pending_error'] = DAAttributeError("name '" + var_name + "' is not defined")
raise docassemble.base.functions.this_thread.misc['pending_error']

def raise_undefined_attribute_error(self, thename):
var_name = object.__getattribute__(self, 'instanceName') + "." + thename
docassemble.base.functions.this_thread.misc['pending_error'] = DAAttributeError("name '" + var_name + "' is not defined")
raise docassemble.base.functions.this_thread.misc['pending_error']

def object_name(self, **kwargs):
"""Returns the instanceName attribute, or, if the instanceName contains attributes, returns a
phrase. E.g., case.plaintiff becomes "plaintiff in the case." """
Expand Down Expand Up @@ -2749,6 +2754,10 @@ def __getitem__(self, index):
# logmessage("Assuming it is there!")
return self.elements[index]

def raise_undefined_index_error(self, index):
var_name = object.__getattribute__(self, 'instanceName') + '[' + str(index) + ']'
raise DAIndexError("name '" + var_name + "' is not defined")

def __str__(self):
self._trigger_gather()
return str(self.comma_and_list())
Expand Down Expand Up @@ -3801,6 +3810,10 @@ def __getitem__(self, index):
return self.elements[index]
return self.elements[index]

def raise_undefined_index_error(self, index):
var_name = object.__getattribute__(self, 'instanceName') + "[" + repr(index) + "]"
raise DAIndexError("name '" + var_name + "' is not defined")

def __setitem__(self, key, the_value):
self.elements[key] = the_value

Expand Down
3 changes: 3 additions & 0 deletions docassemble_base/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"
7 changes: 2 additions & 5 deletions docassemble_base/setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import os
import sys
from fnmatch import fnmatchcase
from distutils.util import convert_path
from setuptools import setup, find_namespace_packages


Expand All @@ -14,7 +12,7 @@ def read(fname):

def find_package_data(where='.', package='', exclude=standard_exclude, exclude_directories=standard_exclude_directories):
out = {}
stack = [(convert_path(where), '', package)]
stack = [(os.path.normpath(where), '', package)]
while stack:
where, prefix, package = stack.pop(0)
for name in os.listdir(where):
Expand Down Expand Up @@ -47,7 +45,6 @@ def find_package_data(where='.', package='', exclude=standard_exclude, exclude_d
return out

install_requires = [
'docassemble==1.6.0',
"3to2==1.1.1",
"aiohappyeyeballs==2.4.3",
"aiohttp==3.11.8",
Expand Down Expand Up @@ -255,7 +252,7 @@ def find_package_data(where='.', package='', exclude=standard_exclude, exclude_d
license='MIT',
url='https://docassemble.org',
install_requires=install_requires,
packages=find_namespace_packages(),
packages=find_namespace_packages(include=['docassemble.*']),
zip_safe=False,
package_data=find_package_data(where=os.path.join('docassemble', 'base', ''), package='docassemble.base'),
)
3 changes: 3 additions & 0 deletions docassemble_demo/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"
6 changes: 2 additions & 4 deletions docassemble_demo/setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os
from fnmatch import fnmatchcase
from distutils.util import convert_path
from setuptools import setup, find_namespace_packages


Expand All @@ -13,7 +12,7 @@ def read(fname):

def find_package_data(where='.', package='', exclude=standard_exclude, exclude_directories=standard_exclude_directories):
out = {}
stack = [(convert_path(where), '', package)]
stack = [(os.path.normpath(where), '', package)]
while stack:
where, prefix, package = stack.pop(0)
for name in os.listdir(where):
Expand Down Expand Up @@ -55,9 +54,8 @@ def find_package_data(where='.', package='', exclude=standard_exclude, exclude_d
author_email='[email protected]',
license='MIT',
url='https://docassemble.org',
packages=find_namespace_packages(),
packages=find_namespace_packages(include=['docassemble.*']),
install_requires=[
'docassemble==1.6.0',
'docassemble.base==1.6.0',
"googledrivedownloader==0.4",
"ics==0.7.2",
Expand Down
14 changes: 7 additions & 7 deletions docassemble_webapp/docassemble/webapp/static/app/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ i.da-chat-inactive:hover {
margin-right: calc(var(--bs-gutter-x) * .5);
}

.da-grid-container.da-form-group-floating legend {
.da-grid-container.da-form-group-floating div.da-legend {
margin-left: calc(var(--bs-gutter-x) * .5);
margin-right: calc(var(--bs-gutter-x) * .5);
}
Expand All @@ -244,7 +244,7 @@ i.da-chat-inactive:hover {
color: var(--bs-red);
}

legend.da-top-label {
div.da-legend.da-top-label {
font-size: inherit;
}

Expand Down Expand Up @@ -789,7 +789,7 @@ div.dafieldpart > label:first-of-type {
margin-top: 0px;
}

div.dafieldpart > legend:first-of-type {
div.dafieldpart > div.da-legend:first-of-type {
margin-top: 0px;
}

Expand Down Expand Up @@ -957,7 +957,7 @@ img.da-sig-spinner {
width: 100%;
}

.dafullwidth + legend {
.dafullwidth + div.da-legend {
width: 100%;
}

Expand Down Expand Up @@ -1946,15 +1946,15 @@ div.form-text .daterm {
margin-bottom: 0.5rem;
}

div.da-grid-container > div.dafieldpart > fieldset.da-field-radio {
div.da-grid-container > div.dafieldpart > div.da-field-radio {
margin-bottom: -0.5rem;
}

div.da-grid-container > div.dafieldpart > fieldset.da-field-checkbox {
div.da-grid-container > div.dafieldpart > div.da-field-checkbox {
margin-bottom: -0.5rem;
}

div.da-grid-container > div.dafieldpart > fieldset.da-field-checkboxes {
div.da-grid-container > div.dafieldpart > div.da-field-checkboxes {
margin-bottom: -0.5rem;
}

Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Loading

0 comments on commit 84fb269

Please sign in to comment.