Skip to content

Commit

Permalink
non-required multiple choice text field now has empty string as the v…
Browse files Browse the repository at this point in the history
…alue; rendering font no longer disabled; added JavaScript to remove commas and other characters from fields before validation
  • Loading branch information
jhpyle committed Aug 2, 2024
1 parent 408434d commit 34ff281
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 17 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# Change Log

## [1.4.112] - 2024-08-02

### Changed
- The default value of a non-`required` multiple-choice text field is
now `''` instead of `'None'`. The default value when the field is
not filled out is based on its `datatype`, e.g., `0` for `datatype:
integer`. The default data type is `text`.

### Fixed
- The `rendering font` feature had been inadvertently disabled.
- Commas entered into numeric fields were causing the field not to
validate; now any invalid characters are removed.

## [1.4.111] - 2024-07-23

### Fixed
Expand Down
9 changes: 8 additions & 1 deletion docassemble_base/docassemble/base/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,14 @@ def get_field_info(self):
else:
checkboxes[safeid(from_safeid(field.saveas) + "[R" + myb64quote(repr(pair['key'])) + "]")] = 'False'
elif not self.extras['required'][field.number]:
checkboxes[field.saveas] = 'None'
if field.datatype == 'text':
checkboxes[field.saveas] = ''
elif field.datatype == 'integer':
checkboxes[field.saveas] = '0'
elif field.datatype in ('number', 'float', 'currency', 'range'):
checkboxes[field.saveas] = '0.0'
else:
checkboxes[field.saveas] = 'None'
if field.datatype in ('object_multiselect', 'object_checkboxes'):
datatypes[safeid(from_safeid(field.saveas) + ".gathered")] = 'boolean'
if self.extras.get('list_collect_is_final', False):
Expand Down
1 change: 0 additions & 1 deletion docassemble_base/docassemble/base/pdftk.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

SYSTEM_VERSION = daconfig.get('system version', None)
REPLACEMENT_FONT_SUPPORTED = SYSTEM_VERSION is not None and packaging.version.parse(SYSTEM_VERSION) >= packaging.version.parse("1.4.73")
REPLACEMENT_FONT_SUPPORTED = False
DEFAULT_RENDERING_FONT = daconfig.get('default rendering font', None)
if REPLACEMENT_FONT_SUPPORTED and DEFAULT_RENDERING_FONT and os.path.isfile(DEFAULT_RENDERING_FONT):
DEFAULT_FONT_ARGUMENTS = ['replacement_font', DEFAULT_RENDERING_FONT]
Expand Down
4 changes: 3 additions & 1 deletion docassemble_base/docassemble/base/standardformatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3527,7 +3527,9 @@ def input_for(status, field, embedded=False, floating_label=None):
input_type = 'datetime-local'
step_string = ''
if field.datatype in ['integer', 'float', 'currency', 'number']:
input_type = 'text" inputmode="numeric" pattern="[\-\d.,]*' # noqa: W605
if field.datatype != 'currency':
extra_class += ' danumeric'
input_type = 'text" inputmode="numeric" pattern="[\-\d.]*' # noqa: W605
if hasattr(field, 'extras') and 'step' in field.extras and 'step' in status.extras and field.number in status.extras['step']:
step_string = ' step="' + str(status.extras['step'][field.number]) + '"'
else:
Expand Down
35 changes: 24 additions & 11 deletions docassemble_webapp/docassemble/webapp/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -7145,6 +7145,7 @@ def index(action_argument=None, refer=None):
vars_set = set()
old_values = {}
new_values = {}
no_input_values = {}
if ('_email_attachments' in post_data and '_attachment_email_address' in post_data) or '_download_attachments' in post_data:
should_assemble = True
error_messages = []
Expand Down Expand Up @@ -7176,10 +7177,12 @@ def index(action_argument=None, refer=None):
checkbox_field = k
break
post_data.add(checkbox_field, checkbox_value)
no_input_values[checkbox_field] = checkbox_value
empty_fields = field_info['hiddens']
for empty_field in empty_fields:
for empty_field, data_type in empty_fields.items():
if empty_field not in post_data:
post_data.add(empty_field, 'None')
no_input_values[empty_field] = 'None'
ml_info = field_info['ml_info']
field_list = interview_status.get_fields_and_sub_fields_and_collect_fields(user_dict)
authorized_fields = [from_safeid(field.saveas) for field in field_list if hasattr(field, 'saveas')]
Expand Down Expand Up @@ -7583,7 +7586,7 @@ def index(action_argument=None, refer=None):
data = repr('')
elif known_datatypes[real_key] == 'integer':
raw_data = raw_data.replace(',', '')
if raw_data.strip() == '':
if raw_data.strip() in ('', 'None'):
raw_data = '0'
try:
test_data = int(raw_data)
Expand All @@ -7599,7 +7602,7 @@ def index(action_argument=None, refer=None):
elif known_datatypes[real_key] in ('number', 'float', 'currency', 'range'):
raw_data = raw_data.replace('%', '')
raw_data = raw_data.replace(',', '')
if raw_data == '':
if raw_data in ('', 'None'):
raw_data = 0.0
try:
test_data = float(raw_data)
Expand Down Expand Up @@ -7673,7 +7676,7 @@ def index(action_argument=None, refer=None):
else:
data = repr(test_data)
elif known_datatypes[real_key] == 'raw':
if raw_data == "None" and set_to_empty is not None:
if raw_data == "None" and (set_to_empty is not None or (orig_key in no_input_values and no_input_values[orig_key] == 'None')):
test_data = None
data = "None"
else:
Expand All @@ -7683,7 +7686,7 @@ def index(action_argument=None, refer=None):
if isinstance(raw_data, str):
raw_data = BeautifulSoup(raw_data, "html.parser").get_text('\n')
raw_data = re.sub(r'\\', '', raw_data)
if raw_data == "None" and set_to_empty is not None:
if raw_data == "None" and (set_to_empty is not None or (orig_key in no_input_values and no_input_values[orig_key] == 'None')):
test_data = None
data = "None"
else:
Expand Down Expand Up @@ -7753,7 +7756,7 @@ def index(action_argument=None, refer=None):
data = repr('')
elif known_datatypes[orig_key] == 'integer':
raw_data = raw_data.replace(',', '')
if raw_data.strip() == '':
if raw_data.strip() in ('', 'None'):
raw_data = '0'
try:
test_data = int(raw_data)
Expand All @@ -7769,7 +7772,7 @@ def index(action_argument=None, refer=None):
elif known_datatypes[orig_key] in ('number', 'float', 'currency', 'range'):
raw_data = raw_data.replace(',', '')
raw_data = raw_data.replace('%', '')
if raw_data == '':
if raw_data in ('', 'None'):
raw_data = '0.0'
test_data = float(raw_data)
data = "float(" + repr(raw_data) + ")"
Expand Down Expand Up @@ -7817,7 +7820,7 @@ def index(action_argument=None, refer=None):
else:
data = repr(test_data)
elif known_datatypes[orig_key] == 'raw':
if raw_data == "None" and set_to_empty is not None:
if raw_data == "None" and (set_to_empty is not None or (orig_key in no_input_values and no_input_values[orig_key] == 'None')):
test_data = None
data = "None"
else:
Expand All @@ -7827,7 +7830,7 @@ def index(action_argument=None, refer=None):
if isinstance(raw_data, str):
raw_data = BeautifulSoup(raw_data.strip(), "html.parser").get_text('\n')
raw_data = re.sub(r'\\', '', raw_data)
if raw_data == "None" and set_to_empty is not None:
if raw_data == "None" and (set_to_empty is not None or (orig_key in no_input_values and no_input_values[orig_key] == 'None')):
test_data = None
data = "None"
else:
Expand Down Expand Up @@ -11437,16 +11440,26 @@ def index(action_argument=None, refer=None):
}
}
});
$('.dacurrency').on('blur', function(){
$('.dacurrency').on('change', function(){
var theVal = $(this).val().toString();
if (theVal.indexOf('.') >= 0){
theVal = theVal.replace(',', '');
theVal = theVal.replaceAll(/[^0-9\.\-]/g, '');
var num = parseFloat(theVal);
var cleanNum = num.toFixed(""" + str(daconfig.get('currency decimal places', 2)) + """).toString();
if (cleanNum != 'NaN') {
$(this).val(cleanNum);
}
else {
$(this).val(theVal);
}
}
else {
$(this).val(theVal.replaceAll(/[^0-9\.\-]/g, ''));
}
});
$('.danumeric').on('change', function(){
var theVal = $(this).val().toString();
$(this).val(theVal.replaceAll(/[^0-9\.\-]/g, ''));
});
// iOS will truncate text in `select` options. Adding an empty optgroup fixes that
if (navigator.userAgent.match(/(iPad|iPhone|iPod touch);/i)) {
Expand Down
6 changes: 3 additions & 3 deletions tests/features/TestExamples.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5805,7 +5805,7 @@ Feature: Example interviews
Then I should see the phrase "What is your date of birth?"
And I set the text box to "08/01/1989"
And I click the button "Continue"
Then I should see the phrase "You are 34 years old."
Then I should see the phrase "You are 35 years old."

# Scenario: Test the interview "Test e-mail attachment"
# Given I start the interview "docassemble.demo:data/questions/testattach.yml"
Expand Down Expand Up @@ -6383,8 +6383,8 @@ Feature: Example interviews
Then I should see the phrase "Please provide the following information."
And I click the "Yes" option under "Do you like apricots?"
And I click the button "Continue"
Then I should see the phrase "likes_apricots is True"
Then I should see the phrase "fruit_favorites is None"
Then I should see the phrase "likes_apricots is True."
Then I should see the phrase "fruit_favorites is ."

Scenario: Test the interview "Non-required radio buttons" filling out field
Given I start the interview "docassemble.base:data/questions/examples/non-required-radio.yml"
Expand Down

0 comments on commit 34ff281

Please sign in to comment.