Hello,
I have a field with a select type in my listing. This selector (dropdown) calls onload a javascript function which calls also a php file to find a list of users. I used a ajax method to get this list fro database on load.
My problem: The list of users is not loaded as options in my dropdown list. Here are my codes. The id here is my project_id. The list of users is the list of project team members related to the project_id.
In FrontList/Settings/Fields, the definition of my selector for each row (indexed by Model.id) is:
In FrontList/List Display/Table/Header:
The 'GetMyList.php' php code is:
I tested this code independently and this one gives:
This result is what I expected, with 2 users with their related id and name. The problem should not come from the php code.
When I have a look on the id of the dropdown list (Model_{Model.id}) from by browser in inspector mode, I don't get the options added.
Do you have an idea what is wrong with that?
Thanks for your help
Bertrand
I have a field with a select type in my listing. This selector (dropdown) calls onload a javascript function which calls also a php file to find a list of users. I used a ajax method to get this list fro database on load.
My problem: The list of users is not loaded as options in my dropdown list. Here are my codes. The id here is my project_id. The list of users is the list of project team members related to the project_id.
In FrontList/Settings/Fields, the definition of my selector for each row (indexed by Model.id) is:
Model.field:<select id="Model_{Model.id}" onload="GetMyList({Model.id})"><option value="">MyList</option></select>
In FrontList/List Display/Table/Header:
<script>
function GetMyList(id) {
jQuery(document).ready(function() {
var $myvalue = jQuery("#Model_"+id);
jQuery.ajax({
url: 'GetMyList.php',
type:'POST',
data:'ID='+id,
dataType: 'json',
success: function(json) {
jQuery.each(json, function(user_id, name) {
$myvalue.append('<option value="'+ user_id +'">'+ name +'</option>');
});
}
});
});
}
</script>
The 'GetMyList.php' php code is:
//
<?php
$project_id = $_POST['ID'];
......
while ($row = mysql_fetch_assoc($results)) {
$user_id = $row['user_id'];
$user_name= $row['name'];
$json[] = array($user_id => $user_name);
}
echo json_encode($json);
?>
I tested this code independently and this one gives:
[{"794":"John Smith"},{"831":"Barbara Gould"}]
This result is what I expected, with 2 users with their related id and name. The problem should not come from the php code.
When I have a look on the id of the dropdown list (Model_{Model.id}) from by browser in inspector mode, I don't get the options added.
Do you have an idea what is wrong with that?
Thanks for your help
Bertrand