Only run the form validation stuff if we have a form.
If there is a default value, use it, regardless of whether the form is hidden (this is how the front end works) (accomplished by moving the hide_epxression check -> continue stuff below the set default_value code)
This commit is contained in:
parent
b03e24bbf4
commit
26eeb2912a
|
@ -199,7 +199,8 @@ class WorkflowService(object):
|
|||
task,
|
||||
add_docs_and_forms=True) # Assure we try to process the documentation, and raise those errors.
|
||||
# make sure forms have a form key
|
||||
if hasattr(task_api, 'form') and task_api.form is not None and task_api.form.key == '':
|
||||
if hasattr(task_api, 'form') and task_api.form is not None:
|
||||
if task_api.form.key == '':
|
||||
raise ApiError(code='missing_form_key',
|
||||
message='Forms must include a Form Key.',
|
||||
task_id=task.id,
|
||||
|
@ -315,11 +316,6 @@ class WorkflowService(object):
|
|||
# task_id='task.id',
|
||||
# task_name=task.get_name())
|
||||
|
||||
# If the field is hidden it should not produce a value.
|
||||
if field.has_property(Task.FIELD_PROP_HIDE_EXPRESSION):
|
||||
if WorkflowService.evaluate_property(Task.FIELD_PROP_HIDE_EXPRESSION, field, task):
|
||||
continue
|
||||
|
||||
# If we have a default_value, try to set the default
|
||||
if field.default_value:
|
||||
try:
|
||||
|
@ -334,6 +330,10 @@ class WorkflowService(object):
|
|||
else:
|
||||
form_data[field.id] = None
|
||||
|
||||
# If the field is hidden it should not produce a value.
|
||||
if field.has_property(Task.FIELD_PROP_HIDE_EXPRESSION):
|
||||
if WorkflowService.evaluate_property(Task.FIELD_PROP_HIDE_EXPRESSION, field, task):
|
||||
continue
|
||||
|
||||
# If we are only populating required fields, and this isn't required. stop here.
|
||||
if required_only:
|
||||
|
|
|
@ -23,6 +23,11 @@
|
|||
<camunda:property id="required_expression" value="not boolean_field" />
|
||||
</camunda:properties>
|
||||
</camunda:formField>
|
||||
<camunda:formField id="always_set" type="string" defaultValue=""always"">
|
||||
<camunda:properties>
|
||||
<camunda:property id="hide_expression" value="True" />
|
||||
</camunda:properties>
|
||||
</camunda:formField>
|
||||
</camunda:formData>
|
||||
</bpmn:extensionElements>
|
||||
<bpmn:incoming>SequenceFlow_0lvudp8</bpmn:incoming>
|
||||
|
@ -39,6 +44,11 @@ if boolean_field:
|
|||
result = required_if_true
|
||||
else:
|
||||
result = required_if_false
|
||||
|
||||
# Note that hidden fields with a default
|
||||
# value should always exist.
|
||||
if not always_set == "always":
|
||||
should_never_get_here
|
||||
</bpmn:script>
|
||||
</bpmn:scriptTask>
|
||||
</bpmn:process>
|
||||
|
|
|
@ -177,7 +177,11 @@ class TestWorkflowSpecValidation(BaseTest):
|
|||
def test_fields_required_based_on_later_fields_correctly_populates(self):
|
||||
"""Say you have a form, where the first field is required only if the
|
||||
SECOND field is checked true. This assures such a case will validate and
|
||||
that the variables that should exist (because they are required) do exist."""
|
||||
that the variables that should exist (because they are required) do exist.
|
||||
|
||||
As a bonus test, we also assert that a default field is always present
|
||||
regardless of it's hidden status.
|
||||
"""
|
||||
self.load_test_spec('empty_workflow', master_spec=True)
|
||||
self.create_reference_document()
|
||||
errors = self.validate_workflow("required_expressions")
|
||||
|
|
Loading…
Reference in New Issue