Edit and save a record, then click a button to create a new record based on a handful of values in this original record.
One of the fields I want to prepopulate from the original record to this new record is a Lookup field. So click the button to create the new record, I want this dropdown to be preselected to match the original record. I am trying to do this in the tablename-dv hook. I have this code <snipped> in the -dv hook
Code: Select all
ob_start(); ?>
<script>
$j(function() {
$j('#Donor-container').select2('val','<?php echo $donor?>');
})
</script>
<?php
$new_layout = ob_get_contents();
ob_end_clean();
Code: Select all
function Donor_reload() {
$j("#Donor-container").select2({
/* initial default value */
initSelection: function(e, c) {
$j.ajax({
url: 'ajax_combo.php',
dataType: 'json',
data: { id: AppGini.current_Donor.value, t: 'Vehicles', f: 'Donor' },
success: function(resp) {
c({
id: resp.results[0].id,
text: resp.results[0].text
});
$j('[name="Donor"]').val(resp.results[0].id);
$j('[id=Donor-container-readonly]').html('<span id="Donor-match-text">' + resp.results[0].text + '</span>');
if(resp.results[0].id == '{empty_value}') { $j('.btn[id=Donors_view_parent]').hide(); }else{ $j('.btn[id=Donors_view_parent]').show(); }
if(typeof(Donor_update_autofills) == 'function') Donor_update_autofills();
}
});
},
width: '100%',
formatNoMatches: function(term) { /* */ return 'No matches found!'; },
minimumResultsForSearch: 5,
loadMorePadding: 200,
ajax: {
url: 'ajax_combo.php',
dataType: 'json',
cache: true,
data: function(term, page) { /* */ return { s: term, p: page, t: 'Vehicles', f: 'Donor' }; },
results: function(resp, page) { /* */ return resp; }
},
escapeMarkup: function(str) { /* */ return str; }
}).on('change', function(e) {
AppGini.current_Donor.value = e.added.id;
AppGini.current_Donor.text = e.added.text;
$j('[name="Donor"]').val(e.added.id);
if(e.added.id == '{empty_value}') { $j('.btn[id=Donors_view_parent]').hide(); }else{ $j('.btn[id=Donors_view_parent]').show(); }
if(typeof(Donor_update_autofills) == 'function') Donor_update_autofills();
});
if(!$j("#Donor-container").length) {
$j.ajax({
url: 'ajax_combo.php',
dataType: 'json',
data: { id: AppGini.current_Donor.value, t: 'Vehicles', f: 'Donor' },
success: function(resp) {
$j('[name="Donor"]').val(resp.results[0].id);
$j('[id=Donor-container-readonly]').html('<span id="Donor-match-text">' + resp.results[0].text + '</span>');
if(resp.results[0].id == '{empty_value}') { $j('.btn[id=Donors_view_parent]').hide(); }else{ $j('.btn[id=Donors_view_parent]').show(); }
if(typeof(Donor_update_autofills) == 'function') Donor_update_autofills();
}
});
}
}
~Paul
AppGini 5.84