Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cannot clone chained select problem

Status
Not open for further replies.

mptwoadmin

Programmer
May 15, 2006
46
US
Hi, I have the following script that works for the most part except the chained select. I think i have distinct id's for everything but when I add a new row the chained select fails. Can I someone lend a hand.
Thank You

I have add, remove, up, down, top, bottom working in the fiddle; and sequential numbering

 
Hi

I would prefer to search for another solution which has a dedicated [tt].unchained()[/tt] too.

Anyway, to solve this problem
[ul]
[li]separate the [tt].clone()[/tt] and [tt].insertAfter()[/tt] calls, so you can [highlight #fcc]break the inherited chaining[/highlight] before inserting into DOM[/li]
[li][highlight #cfc]define new chaining[/highlight] for the new elements[/li]
[/ul]
Code:
$([green][i]'.addnew'[/i][/green]).live([green][i]'click'[/i][/green], [b]function[/b] () {
    [b]var[/b] thisRow = $([b]this[/b]).parent().parent();
    [b]var[/b] img_ins = $([green][i]'.image_insert'[/i][/green]),
        i = img_ins.length + 1;
    [b]var[/b] rowCnt = $([green][i]'#realtable tbody>tr'[/i][/green]).length;
    newRow = thisRow.clone([b]true[/b]);
    [highlight #fcc]newRow.find([green][i]'*'[/i][/green]).unbind();[/highlight]
    newRow.insertAfter(thisRow);
    [gray]//$(row).appendTo('#realtable');[/gray] 
    newRow.find([green][i]"select"[/i][/green]).first().attr([green][i]'id'[/i][/green], [green][i]'mark'[/i][/green] + rowCnt);
    newRow.find([green][i]"select"[/i][/green]).last().attr([green][i]'id'[/i][/green], [green][i]'series'[/i][/green] + rowCnt);
    newRow.find([green][i]"input"[/i][/green]).last().attr([green][i]'id'[/i][/green], [green][i]'stepvalue'[/i][/green] + rowCnt);
    [highlight #cfc]$([green][i]'#series'[/i][/green] + rowCnt).chained([green][i]'#mark'[/i][/green] + rowCnt);
[/highlight]
    [gray]//start renumber on insert[/gray]   
    [b]var[/b] x = 0;
    $([green][i]'#realtable tr'[/i][/green]).each([b]function[/b] () {
        $(this).find([green][i]"th:first"[/i][/green]).text(x);
        newRow.find([green][i]'input.increment'[/i][/green]).val(parseInt(thisRow.find([green][i]'input.increment'[/i][/green]).text()) + x);

        x++;

    }); [gray]//end renumber on insert[/gray]
});

Sadly from the copied [tt]select[/tt]s the second one will only be populated with the elements that its original had when copying. Sorry, no time to solve this too now.

Feherke.
feherke.ga
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top