I have a smarty template that uses jQuery clones; i.e. a click on a button will call jQuery and jQuery will add a select field to a page. However, the select field is supposed to be dynamically populated within the smarty template.
I have outlined below what i'm trying to achieve.
addProject.php
// Load supervisor list into an object and pass it to smarty
$smarty->assign_by_ref('supervisor', $supervisor->results());
$smarty->display('superusers/addProject.tpl');
superusers/addProject.tpl
<div>
<p class="add add-data add-another-supervisor2"><i class="sprite plus2"></i> <span>Add <b class="hide">another</b> supervsior</span></p>
</div>
<script src="js/cloneformcontrols.js"></script>
js/cloneformcontrols.js
$("#main").on("click", ".add-data", function() {
var mytarget = $(this).closest('.clonable').find('.clone:last');
var myparent = $(this).closest('.clonable');
var filename = "../smarty/templates/default/superusers/clones/add-supervisor.tpl";
var theCloneHtml = '<div class="clone" id="cloneID' + formNameIncrement + '">';
var theCloneId = 'cloneID' + formNameIncrement;
if ($(this).hasClass('add-another-supervisor2')) {filename = "../smarty/templates/default/superusers/clones/add-another-supervisor.tpl";}
myparent.addClass('data-added');
mytarget.after($(theCloneHtml).load(filename, function() {
$(this).hide().fadeIn('slow');
updateNameAttribute(theCloneId); // need to update the name atribute or validation won't work
}));
formNameIncrement++;
});
clones/add-another-supervisor.tpl
<div class="standard-row add-admin-row input-row">
<label class="ib ib217"> <span class="plain-select">
<select class="inp" data-myname="supervisor[]" name="supervisor[]">
<option value="">Select one</option>
{section name="i" loop=$supervisor}
<option value="{$supervisor[i]->id}">{$supervisor[i]->name}</option>
{/section}
</select>
</span> </label>
<p class="add remove-this-data fl"><i class="sprite delete2"></i> <span> </span></p>
</div>
The only part that is not working is the clones/add-another-supervisor.tpl page doesn't receive the object $supervisor and therefore none of the select options get filled.
Does anyone know how I can fix this?