foreach ($addressFields as $field) {
if (array_key_exists($field, $addressSequence)) {
$addField = $field;
+ $type = 'Text';
if (in_array($field, array(
'state_province', 'country'))) {
$addField = "{$field}_id";
+ $type = 'Select2';
}
$elements["onbehalf_{$field}-{$locTypeId}"] = array(
- 'type' => 'Text',
+ 'fld' => $field,
+ 'locTypeId' => $locTypeId,
+ 'type' => $type,
'value' => isset($location['address'][1]) ? $location['address'][1][$addField] : null,
);
unset($profileFields["{$field}-{$locTypeId}"]);
var submittedOnBehalfInfo = {/literal}'{$submittedOnBehalfInfo}'{literal};
if (submittedOnBehalfInfo) {
submittedOnBehalfInfo = cj.parseJSON(submittedOnBehalfInfo);
- }
- if (submittedCID == contactID) {
- cj.each(submittedOnBehalfInfo, function(key, value) {
- cj('#onbehalf_' + key ).val(value);
- });
- return;
+
+ if (submittedCID == contactID) {
+ cj.each(submittedOnBehalfInfo, function(key, value) {
+ cj('#onbehalf_' + key ).val(value);
+ });
+ return;
+ }
}
resetValues();
cj('#' + ele + " option[value='" + selectedOption + "']").prop('selected', true);
}
}
+ else if (data[ele].type == 'Select2') {
+ if (data[ele].fld == 'country') {
+ cj('#' + ele ).select2('val', data[ele].value).change(function() {
+ var stateField = 'onbehalf_state_province-' + data[ele].locTypeId;
+ if (stateField.length > 0 ) {
+ cj('#' + stateField).select2('val', data[stateField].value);
+ }
+ }).change();
+ }
+ }
else if (data[ele].type == 'Autocomplete-Select') {
cj('#' + ele ).val( data[ele].value );
cj('#' + ele + '_id').val(data[ele].id);