The first thing they need is that there is a text type field in the destination table, it doesn't need anything special.
Then they need to put the function somewhere where it can be accessed at any time, for example in header-extras.php.
Inside the tablename-dv.js file, place the function call. the only parameters that we pass are the name of the table and the field where the data is to be saved.
I hope you find it useful both to me.
function definition:
Code: Select all
/**
* Construct a selectable drop down list with registered users.
* @param {string} f - Field name to replace wit drop-down list.
* @param {string} t - table name destiny.
*/
function users_dropdown(f, t) {
var $selectField = $j('#' + f + '').hide();
var $span = $j('<span/>', { id: 's2_users_' + f });
$selectField.closest('div').append($span);
var val = $selectField.val();
$span.select2({
width: '100%',
formatNoMatches: function(term) { return 'No matches found!'; },
minimumResultsForSearch: 5,
loadMorePadding: 200,
escapeMarkup: function(m) { return m; },
ajax: {
url: 'admin/getUsers.php',
dataType: 'json',
cache: true,
data: function(term, page) { return { s: term, p: page, t: t }; },
results: function(resp, page) { return resp; }
}
}).on('change', function(e) {
$j('[name="' + f + '"]').val(e.added.id);
});
if (val) {
$span.select2('data', { text: val, id: val });
}
}
Code: Select all
t = 'contacto';
f = 'user';
users_dropdown(f, t);