-
Notifications
You must be signed in to change notification settings - Fork 3
Improve Relink UI and add People Picker (CFM-125) #316
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -225,6 +225,22 @@ public static function entityAndActionToTitle($entity, | |
return [$title, $supertitle, $subtitle]; | ||
} | ||
|
||
/** | ||
* Extract and return the Person ID from a People Picker string | ||
* | ||
* @since COmanage Registry v5.2.0 | ||
* @param string $s Person string from the People Picker widget, e.g. "Jane+Doe+(ID:+2125)" | ||
* @return int extracted Person ID (converted to int from the extracted string) | ||
*/ | ||
|
||
public static function extractPeoplePickerPersonId(string $s): int { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What will the function do if the string does not match? |
||
// Regular expression for handling People Picker input | ||
$re = '/^.*\(ID: (\d+)\)$/m'; | ||
// Extract the People Picker Person ID | ||
preg_match_all($re, $s, $matchesTarget, PREG_SET_ORDER, 0); | ||
return (int)$matchesTarget[0][1]; | ||
} | ||
|
||
/** | ||
* Determine the class name from a foreign key (eg: report_id -> Reports). | ||
* | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,9 +43,33 @@ | |
]); | ||
|
||
print $this->Form->hidden('external_identity_id', ['default' => $vv_external_identity->id]); | ||
// This label isn't localized, but it should go away when the UX is fixed | ||
print $this->Form->control('target_person_id', ['type' => 'integer', 'label' => 'Target Person ID']); | ||
|
||
print $this->Form->submit(); | ||
?> | ||
<ul id="edit_ei-relink" class="fields form-list"> | ||
<?php | ||
$this->Form->unlockField('target_person_id'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the field does not have to be unlocked. The reason why this is needed is because the backend does not know this field name. We can use the $personId = StringUtilities::extractPeoplePickerPersonId($reqData['person_id']) If we do not mind having the unlocked field then it works well. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure I follow the comment about the backend not knowing the field name, what do you mean by "the backend"? This is a custom form that is generated by the relink view to pass a variable that is parsed by There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
What I meant is this: Currently, we’re including a Vue input element in the form, which gets submitted alongside the form data. However, since this input field isn’t rendered using the Form Helper, CakePHP detects a "form tampered" error when the field is submitted. After some research, I discovered that one way to prevent an input field from being submitted is to remove its [!important] The hidden field should be visually hidden and not type hidden or display none. For the type hidden use case CAKEPHP will throw a tampered form error. For the display none the field will not be submitted. The visually hidden fields take DOM space, which do not make them the best solution. $vv_autocomplete_arguments = [
'fieldName' => target_person_id',
'fieldLabel' => __d('field', 'ExternalIdentitySources.target_person_id'),
'autocomplete' => [
'configuration' => [
'action' => 'GET',
'for' => 'co'
]
]
]; then inside the print $this->Form->control($fieldName, [
'id' => $fieldName,
'value' => '',
'type' => 'text',
'class' => 'visually-hidden',
'label' => false,
]
);
autocompleteOptions: {
inputProps: {
//name: '<?php //= $fieldName ?>//',
// This is not translated to data-personid but to datapersonid.
dataPersonid: '<?= $inputValue ?>'
},
...
} and then inside the people picker element setPerson() {
...
document.getElementById(this.options.hiddenFieldId).setAttribute('value', this.person.value);
...
} hide the field: .visually-hidden {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
border: 0;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap; /* Prevent text wrapping */
} in public function constructSPAField(string $element, string $vueElementName): string {
...
'htmlId' => $matchesId[0][1] . '_picker',
...
} |
||
$vv_autocomplete_arguments = [ | ||
'fieldName' => 'target_person_id', | ||
'fieldLabel' => __d('field', 'ExternalIdentitySources.target_person_id'), | ||
'autocomplete' => [ | ||
'configuration' => [ | ||
'action' => 'GET', | ||
'for' => 'co' | ||
] | ||
] | ||
]; | ||
print $this->element('form/listItem', ['arguments' => $vv_autocomplete_arguments]); | ||
|
||
?> | ||
<li class="fields-submit"> | ||
<div class="field"> | ||
<div class="field-name"> | ||
</div> | ||
<div class="field-info"> | ||
<?= $this->Form->submit() ?> | ||
</div> | ||
</div> | ||
</li> | ||
</ul> | ||
|
||
<?php | ||
print $this->Form->end(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be
ExternalIdentities
instead ofExternalIdentitySources