AnsweredAssumed Answered

Show dropdown option in editview even if not present

Question asked by Rainolf Ray on Apr 29, 2015
Latest reply on Sep 23, 2015 by Jeff Bickart
Hi to all,
for various reason i need to keep my sugarcrm-6.5 installation and for the moment i cannot make any upgrade.

i've created a custom dropdown in Accounts module with a respective blank list options:

dbg_service_c with dbg_service_list_c(no data, only an item used as placeholder)

The dropdown lists must contains thousands of records and to achieve my needs i cannot populate an hardcoded array in SugarCRM.

So, instead, i've creted a scrpt that retrieve data from mysql database and limit the number of results based on initial search.

To do this i've used jquery select2 that permits to search a term before make an ajax call.

After select2.js and respective css inclusion this is my select2 script:

$(document).ready(function(){
$("#dbg_service_c").select2({
placeholder: "Click to select a service",
allowClear: true,
minimumResultsForSearch: Infinity,
width: '350px',
ajax: {
url: "http://servername/dropdown_srv.php";,
dataType: 'json',
delay: 250,
data: function (params) {
var queryParameters = {
term: params.term, //search term
service: 'list_dropdown',
page_limit: 50 // page size
}
return queryParameters;
},
processResults: function (data) {
return {
results: data
};
},
cache: true,
},
minimumInputLength: 0,
maximumInputLength: 10,
});
});

and this is part of my php script:

if (isset($_GET)) {
$service = $_GET;
$term = $_GET;
$page_limit = $_GET;
switch ($service) {
case 'list_dropdown':
// Select all columns to populate service dropdown list
$datas = $database->select("table_services",
[
"code(id)",
"description(text)",
],[
"ORDER" => "id ASC",
"LIMIT" => $page_limit
]);
foreach($datas as $data) {
$dropdown_list_srv[] = array(
'id'=> $data,
'text' => $data,
);
}
break;
}
echo json_encode($dropdown_list_srv);

This works quite well except for my edit views.

In Listview and DetailView i can see my chosen value while in EditView not.
It shows me only the dropdown placeholder.

Doing some research it seems that the value can be showed only if its contained inside a dropdown list array defined into dwopdown editor in SugarCRM.

To make a test i've created a custom edit.view.php files with something like:

require_once('include/MVC/View/views/view.edit.php');

class AccountsViewEdit extends ViewEdit {
function preDisplay() {
parent::preDisplay();
$this->bean->test_dropdown_filed_c = 'myvalue';
}
}

and it doesn't work while:

require_once('include/MVC/View/views/view.edit.php');

class AccountsViewEdit extends ViewEdit {
function preDisplay() {
parent::preDisplay();
$this->bean->test_simple text_filed_c = 'myvalue';
}
}

works like excepted.....

Is it true?

How i can solve this problem?

Am i missing anything?

Thank you

Outcomes