Myke623
Well-known member
Dynamically inserting new content with ajax is all well and good when working in a flat list, like so:
And the relevant js code would be:
But what if one has lists across multiple tabs, and you want to insert the new content in a specific tab? Consider:
In my particular case, new content is inserted via a form overlay. On this form you can select which category the item belongs to, via a drop-down menu. Once the form is submitted, I would like for the new item to be inserted in the correct tab.
I know that I can pass variables into the javascript using data-foo tags, but how do I determine the value to set the variable as? For example, say the template looks as follows:
What I'd really like to do is set the data-list attribute dynamically based on the option value that's selected in the Categories drop down.
Is this possible? If not, then is there an alternative method?
HTML:
<ol id="myList">
<li class="listItem"></li>
<li class="listItem"></li>
<li class="listItem"></li>
<!-- insert here -->
</ol>
And the relevant js code would be:
Code:
$(e.ajaxData.templateHtml).xfInsert('insertAfter', '#myList li:last');
But what if one has lists across multiple tabs, and you want to insert the new content in a specific tab? Consider:
HTML:
<ul id="myCategories">
<li id="firstCategory">
<ol class="listItems">
<li class="listItem"></li>
<li class="listItem"></li>
<li class="listItem"></li>
<!-- how do you insert here? -->
</ol>
</li>
<li id="secondCategory">
<ol class="listItems">
<li class="listItem"></li>
<li class="listItem"></li>
<li class="listItem"></li>
...
</ol>
</li>
</ul>
In my particular case, new content is inserted via a form overlay. On this form you can select which category the item belongs to, via a drop-down menu. Once the form is submitted, I would like for the new item to be inserted in the correct tab.
I know that I can pass variables into the javascript using data-foo tags, but how do I determine the value to set the variable as? For example, say the template looks as follows:
Code:
<form action="{xen:link 'myAddon/save'}" method="post" class="xenForm AutoValidator" id="AppendItem" data-list="????">
<fieldset>
<dl class="ctrlUnit">
<dt><label for="ctrl_category">Category:</label></dt>
<dd>
<select name="cat_id" class="textCtrl autoSize" id="ctrl_category">
<option value="firstCategory">First Category</option>
<option value="secondCategory">Second Category</option>
</select>
</dd>
</dl>
...
</form>
What I'd really like to do is set the data-list attribute dynamically based on the option value that's selected in the Categories drop down.
Is this possible? If not, then is there an alternative method?