Skip to content

Commit

Permalink
Merge branch 'release/0.4.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
ChemiKyle committed Oct 28, 2021
2 parents c129ac0 + 5b4cb42 commit c59d5f2
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ All notable changes to the Search and Populate Data From Another Project module
documented in this file. This project adheres to [Semantic Versioning](http://semver.org/).


## [0.4.0] - 2021-10-28
### Added
- Add support for populating dropdown fields, both autocompleting and regular (Kyle Chesney)


## [0.3.1] - 2021-04-02
### Changed
- Remove trailing comma from final param to getDataDictionary call to support PHP < 7.3 (Kyle Chesney)
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.3.1
0.4.0
43 changes: 43 additions & 0 deletions js/custom_data_search.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ function ajaxGet(record_id) {
function pasteValues(values) {
for (let [key, value] of Object.entries(values)) {
let $target_field = $(`input[name='${key}']`);
if ($target_field.length == 0) {
// not found by name attr, field may be present as a dropdown
selectFromDropdown(key, value);
}
// radio and regular text boxes
if ($target_field.attr('class') == 'hiddenradio') {
// collect all radio fields in all layouts
let $inputs = $target_field.siblings('[class*="choice"]');
Expand All @@ -120,6 +125,44 @@ function pasteValues(values) {
}
}

function selectFromDropdown(key, value) {
const $target_row = $(`tr[sq_id='${key}']`);
const $ac_target_field = $($target_row.find("input")[0]); // ac = auto complete
const $select_field = $(`select[name='${key}']`);

// used to handle cases where the value provided is the displayed value of the desired option,
// rather than the coded value (value attribute)
const displayed_option_value = $select_field
.children()
.filter( (i, e) => {
return ( $(e).html() == value );
} )
.val();

// autocomplete fields
if ($ac_target_field.attr('class') == 'x-form-text x-form-field rc-autocomplete ui-autocomplete-input') {
// the non-coded value must be put in the text box to allow the user to see the pipe occured
// if displayed_value is undefined, this function sets the value to nothing
const displayed_value = $select_field
.children(`[value='${value}']`)
.html();
$ac_target_field.val(displayed_value);

if ($ac_target_field.val() != value && displayed_option_value != undefined) {
// TODO: handle the possibilty that this value could go in an "other" field behind branching logic
$ac_target_field.val(value);
}
return;
}

// non autocomplete fields
$select_field.val(value);
if ($select_field.val() != value && displayed_option_value != undefined) {
// TODO: handle the possibilty that this value could go in an "other" field behind branching logic
$select_field.val(displayed_option_value);
}
}

function showDataConfirmModal( copyData ) {
// show the modal
$( "#dialog-data-stp" ).dialog( "open" );
Expand Down

0 comments on commit c59d5f2

Please sign in to comment.