Hi all,
I’m finalizing my first own Django app and I have some strange issues, as the behavior on my production server is different than in my local Dev environment.
My main issue is about a page displaying 2 multiple select boxes, and buttons dedicated to move items from one to the other thanks to Javascript functions: it works fine in DEV but not in Prod. On top of that, the display is also different, and looks sometimes weird on the Prod server.
The page is dedicated to list users and add them to a group. The icons intend to move one / all user(s) from the list to the group, and vice versa. It works perfectly in DEV but not at all in PROD.
I start with the JS code related to the buttons (I also consider a double click on a single item to move it from one group to the other and it doesn’t work either, so it’s included hereafter):
// Add all (from source to destination)
$('#add_all').on("click", function(e) {
e.preventDefault();
$('#id_users').find('option').removeAttr('selected');
$('#id_all_users option').each(function() {
add_option('#id_all_users', '#id_users', $(this));
$('#id_users_in_group').val($('#id_users_in_group').val() + "-" + String($(this).val()))
})
})
// Add selected (from source to destination)
$('#add_selected').on("click", function(e) {
e.preventDefault();
$('#id_users').find('option').removeAttr('selected');
let values = $('#id_all_users').val();
$('#id_all_users option').each(function() {
if ( values.includes( $(this).val() ) ) {
add_option('#id_all_users', '#id_users', $(this));
$('#id_users_in_group').val($('#id_users_in_group').val() + "-" + String($(this).val()))
}
})
})
// Add selected by double click
$("#id_all_users option").dblclick(function(e) {
e.preventDefault();
$('#id_users').find('option').removeAttr('selected');
add_option('#id_all_users', '#id_users', $(this));
$('#id_users_in_group').val($('#id_users_in_group').val() + "-" + String($(this).val()))
})
// Remove all (empty list, back to global list)
$('#remove_all').on("click", function(e) {
e.preventDefault();
$('#id_all_users').find('option').removeAttr('selected');
$('#id_users option').each(function() {
add_option('#id_users', '#id_all_users', $(this));
$('#id_users_in_group').val($('#id_users_in_group').val().replace(String($(this).val()), ""))
})
})
// Remove selected (from source to destination)
$('#remove_selected').on("click", function(e) {
e.preventDefault();
$('#id_all_users').find('option').removeAttr('selected');
let values = $('#id_users').val();
$('#id_users option').each(function() {
if ( values.includes( $(this).val() ) ) {
add_option('#id_users', '#id_all_users', $(this));
$('#id_users_in_group').val($('#id_users_in_group').val().replace(String($(this).val()), ""))
}
})
})
// Remove selected by double click
$("#id_users option").dblclick(function(e) {
e.preventDefault();
$('#id_all_users').find('option').removeAttr('selected');
add_option('#id_users', '#id_all_users', $(this));
$('#id_users_in_group').val($('#id_users_in_group').val().replace(String($(this).val()), ""))
})
Here are some screenshots to present display issues:
Development - No user in group
Production - No user in group
Development - All users in group
Production - All users in group
I have another case, in the same project, where the display issue occurs only in DEV and there is no issue in the Production environment.
Again 2 screenshots:
DEV Dropdown:
PROD Dropdown:
Many thanks in advance for your support