Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions app/Model/CoPetition.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -2994,6 +2998,7 @@ protected function validateModel($pmodel, $requestData, $efAttrs) {
// missing) related models.
$errFields = $this->$pmodel->invalidFields();

$fail = false;
if(!empty($errFields)) {
$fail = true;
}
Expand All @@ -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'));
Expand Down
19 changes: 17 additions & 2 deletions app/View/CoPetitions/petition-attributes.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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 "<span class=\"required\">*</span>\n";
}

Expand Down Expand Up @@ -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;

Expand Down