From 2f29f055f3a60d139b131db3c95ca5a816d287be Mon Sep 17 00:00:00 2001 From: Michiel Uitdehaag Date: Wed, 5 Sep 2018 16:20:17 +0200 Subject: [PATCH] creates an empty field in petition List selections, even if the field is required. Also print the required asterix for non-mvpa fields as is done for mvpa fields --- app/Model/CoPetition.php | 17 +++++++++++------ app/View/CoPetitions/petition-attributes.inc | 19 +++++++++++++++++-- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/app/Model/CoPetition.php b/app/Model/CoPetition.php index 80af75219..546e6acb3 100644 --- a/app/Model/CoPetition.php +++ b/app/Model/CoPetition.php @@ -1625,6 +1625,14 @@ public function saveAttributes($id, $enrollmentFlowId, $requestData, $petitioner $coData = array(); $coRoleData = array(); + // set enrollmentflow related base data to pass basic validation + $requestData['EnrolleeCoPerson']['co_id'] = $petition['CoPetition']['co_id']; + $requestData['EnrolleeCoPerson']['status'] = StatusEnum::Pending; + + // if no CoPerson available yet, trick validation using a '0' + $requestData['EnrolleeCoPersonRole']['co_person_id'] = empty($coPersonId) ? 0 : $coPersonId; + $requestData['EnrolleeCoPersonRole']['status'] = StatusEnum::Pending; + // Validate the provided attributes $CmpEnrollmentConfiguration = ClassRegistry::init('CmpEnrollmentConfiguration'); @@ -1731,9 +1739,6 @@ public function saveAttributes($id, $enrollmentFlowId, $requestData, $petitioner } if(!empty($coData) && !$coPersonId) { - // Insert some additional attributes - $coData['EnrolleeCoPerson']['co_id'] = $petition['CoPetition']['co_id']; - $coData['EnrolleeCoPerson']['status'] = StatusEnum::Pending; // Save the CO Person Data @@ -1792,9 +1797,8 @@ public function saveAttributes($id, $enrollmentFlowId, $requestData, $petitioner } if(!empty($coRoleData) && !$coPersonRoleId) { - // Insert some additional attributes + // Link the Role to the Person $coRoleData['EnrolleeCoPersonRole']['co_person_id'] = $coPersonId; - $coRoleData['EnrolleeCoPersonRole']['status'] = StatusEnum::Pending; // Set the current timezone for CoPersonRole::afterSave $this->EnrolleeCoPersonRole->setTimeZone($this->tz); @@ -2994,6 +2998,7 @@ protected function validateModel($pmodel, $requestData, $efAttrs) { // missing) related models. $errFields = $this->$pmodel->invalidFields(); + $fail = false; if(!empty($errFields)) { $fail = true; } @@ -3002,7 +3007,7 @@ protected function validateModel($pmodel, $requestData, $efAttrs) { $v = $this->validateRelated($pmodel, $requestData, $ret, $efAttrs); - if($v) { + if($v && !$fail) { $ret = $v; } else { throw new RuntimeException(_txt('er.validation')); diff --git a/app/View/CoPetitions/petition-attributes.inc b/app/View/CoPetitions/petition-attributes.inc index c942bccb3..400b3d0a8 100644 --- a/app/View/CoPetitions/petition-attributes.inc +++ b/app/View/CoPetitions/petition-attributes.inc @@ -211,7 +211,9 @@ // Is the MVPA required? We'll just check the first attribute since they // should all be the same. - if($mvpa && $coe_attributes[0]['mvpa_required'] && $this->action != 'view') { + if( (($mvpa && $coe_attributes[0]['mvpa_required']) + || (!$mvpa && $coe_attributes[0]['required'])) + && $this->action != 'view') { print "*\n"; } @@ -294,7 +296,20 @@ $args['value'] = $ea['default']; $args['disabled'] = !$ea['modifiable']; } - $args['empty'] = !$ea['required']; + + // An attribute is required if (1) it is part of an MVPA that is required + // and the field itself is required, or (2) it is not part of an MVPA and + // the field itself is required + $args['required'] = false; + if(isset($ea['mvpa_required']) && $ea['mvpa_required']) { + $args['required'] = $ea['required']; + } else { + $args['required'] = $ea['required']; + } + + // Always show an empty field, even if required + // This forces users to choose (CO-1655) + $args['empty'] = ''; $args['class'] = 'co-selectfield'; $args['aria-label'] = $m;