Niall Gallagher
asked on
When I clone row autocomplete is not working and when I postback it doesn't se the new row
Hi again
I have a table with a row for entering an agents name and more details
and jquery which is supposed to clone the last row
When I clone the last row the autocomplete does not work anymore. Also once I got the autocomplete to work, but I can't remember what I did, but when I pressed to save the data, when it was posted back it seemed like it didn't see the new row of data.
Any help is greatly appreciated,
Thanks in advance
I have a table with a row for entering an agents name and more details
</tr>
@{ int i = 0;
<tr class="tr_clone">
<td class="td-label">
@Html.Label("Agent Name")
</td>
<td class="td-data" colspan="1">
@Html.TextBox("mytxtbox1",null, new { @class = "AgentName" })
@* @Html.HiddenFor(model => model.merchantpercentages[1].AGENT_ID, new { @class = "Agent", @id="txtAgent1" })*@
@Html.TextBoxFor(model => model.merchantpercentages[i].AGENT_ID,new { @class = "Agent"})
</td>
<td colspan="3">
@Html.TextBoxFor(model => model.merchantpercentages[i].FIRST_YEAR, new { @class = "year1"})
@Html.TextBoxFor(model => model.merchantpercentages[i].SECOND_YEAR, new { @class "year2" })
@Html.TextBoxFor(model => model.merchantpercentages[i].THIRD_YEAR, new { @class = "year3" })
@Html.TextBoxFor(model => model.merchantpercentages[i].FOURTH_YEAR, new { @class = "year4" })
@Html.TextBoxFor(model => model.merchantpercentages[i].FIFTH_YEAR, new { @class = "year5" })
</td>
<td>
<button type="button", id="Add", class="AddRow">Add</button>
</td>
</tr>
i++;
}
</table>
and jquery which is supposed to clone the last row
$('table').on("click", ".AddRow",CloneRow)
function CloneRow()
{
var clone = $(this).closest('.tr_clone').clone()
$(this).closest('.AgentName').autocomplete('destroy')
clone.insertAfter(".tr_clone:last");
$(clone).find(".AddRow").remove();
clone.closest('.AgentName').addClass('.AgentName')
}
When I clone the last row the autocomplete does not work anymore. Also once I got the autocomplete to work, but I can't remember what I did, but when I pressed to save the data, when it was posted back it seemed like it didn't see the new row of data.
Any help is greatly appreciated,
Thanks in advance
ASKER
Now I look at it with a fresher head (After going away from it for a day I can see so many reasons why it's not working I got the Jquery to work by changing the CloneRow function to
I am now working on getting it to see all rows to be saved, will let you know how I get on
function CloneRow()
{
var clone = $(this).closest('.tr_clone').clone()
$(this).closest('.AgentName).autocomplete('destroy')
clone.insertAfter('tr_clone:last');
$(clone.find('AddRow').remove(); //removes the button from the cloned row.
$(clone).find('AgentName').val(); //Clear the agent name box in the cloned row; TODO clear all in row
ApplyAutoComplete('.AgentName') // Earlier destroyed autocomplete but now with a new row I want to activate it again
I am now working on getting it to see all rows to be saved, will let you know how I get on
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I finally figured it out.
ASKER