I have following HTML:
<form action="/Config.aspx/SDKHome/SaveSections" id="SaveSections" method="post">
<input name="[0].SchemaName" type="hidden" value="contactSection" />
<ul creator="attrCreator" data-dojo-type="dojo.dnd.Source" class="section container dojoDndSource"
style="list-style-type: none;">
<li class="dojoDndItem">
<input name="[0].DefinedAttributes[0].SchemaName" type="hidden" value="firstname" />
</li>
<li class="dojoDndItem">
<input name="[0].DefinedAttributes[1].SchemaName" type="hidden" value="jobtitle" />
</li>
</ul>
</form>
I want to add this item to the list:
<li class="dojoDndItem">
<input name="[X].DefinedAttributes[Y].SchemaName" type="hidden" value="itemToAdd" />
</li>
How can I replace X and Y (and increment this values by all following items), to have following html as result:
<form action="/Config.aspx/SDKHome/SaveSections" id="SaveSections" method="post">
<input name="[0].SchemaName" type="hidden" value="contactSection" />
<ul creator="attrCreator" data-dojo-type="dojo.dnd.Source" class="section container dojoDndSource"
style="list-style-type: none;">
<li class="dojoDndItem">
<input name="[0].DefinedAttributes[0].SchemaName" type="hidden" value="firstname" />
</li>
<li class="dojoDndItem">
<input name="[0].DefinedAttributes[1].SchemaName" type="hidden" value="itemToAdd" />
</li>
<li class="dojoDndItem">
<input name="[0].DefinedAttributes[2].SchemaName" type="hidden" value="jobtitle" />
</li>
</ul>
</form>
Try this :
Not sure the selectors I used will work in all browsers, but you get the idea… regex to get each X and Y, increment, and place at the right position using dom selectors. Just adapt that to your dnd logic…
See demo here, with visible inputs rather than hidden : http://jsfiddle.net/psoares/FSCdW