Categories > TinyButStrong general >

Strange Behaviour With Alternating Rows

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Maz
Date: 2005-11-18
Time: 09:28

Strange Behaviour With Alternating Rows

I'm not sure if this is an error in my code, or a problem with TBS.

I am creating an alternate coloured row table, and have the following code:

                    <tr>
                        <td class="light">[pending.product_title]</td>
                        <td class="light">[pending.name;noerr]</td>
                        <td class="light">[pending.product_date;frm='ddxx mmmm';noerr]</td>
                        <td class="light">[pending.cat_name;block=tr;noerr]</td>
                        <td class="light">
                            <select class="select" name="product_state" id="product_state">
                                <option value="[action.id]">[action.act;block=option]</option>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td class="dark" colspan="5">[pending;block=tr;nodata][lang.cell_no_results]</td>
                    </tr>
                    <tr>
                        <td class="dark">[pending.product_title]</td>
                        <td class="dark">[pending.name;noerr]</td>
                        <td class="dark">[pending.product_date;frm='ddxx mmmm';noerr]</td>
                        <td class="dark">[pending.cat_name;block=tr;noerr]</td>
                        <td class="dark">
                            <select class="select" name="product_state" id="product_state">
                                <option value="[action.id]">[action.act;block=option]</option>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td class="dark" colspan="5">[pending;block=tr;nodata][lang.cell_no_results]</td>
                    </tr>
Only if I remove the

                        <td class="dark">
                            <select class="select" name="product_state" id="product_state">
                                <option value="[action.id]">[action.act;block=option]</option>
                            </select>
                        </td>

will the alternate rows show up. Otherwise, it doesn't seem to move past the first table, and all rows have the class="light" applied.

Yet, on a completely different page, I have

                        <tr>
                            <td class="dark">
                                [inactive.name;noerr]
                            </td>
                            <td class="dark">
                                [inactive.joined;frm='ddxx mmmm yyyy']
                            </td>
                            <td class="dark">
                                [inactive.last_activity;frm='ddxx mmmm yyyy']
                            </td>
                            <td class="dark aligncenter">
                                [inactive.posts;noerr;block=tr]
                            </td>
                            <td class="dark aligncenter">
                                <input type="checkbox" name="allbox[]" id="allbox[]" value="[inactive.id]" />
                            </td>
                        </tr>
                        <tr>
                            <td colspan="5" class="dark">
                                [inactive;block=tr;nodata][lang.cell_no_results]
                            </td>
                        </tr>
                        <tr>
                            <td class="light">
                                [inactive.name;noerr]
                            </td>
                            <td class="light">
                                [inactive.joined;frm='ddxx mmmm yyyy']
                            </td>
                            <td class="light">
                                [inactive.last_activity;frm='ddxx mmmm yyyy']
                            </td>
                            <td class="light aligncenter">
                                [inactive.posts;noerr;block=tr]
                            </td>
                            <td class="light aligncenter">
                                <input type="checkbox" name="allbox[]" id="allbox[]" value="[inactive.id]" />
                            </td>
                        </tr>
                        <tr>
                            <td colspan="5" class="dark">
                                [inactive;block=tr;nodata][lang.cell_no_results]
                            </td>
                        </tr>
                        <tr>
                            <td class="dark alignright" colspan="5"><input type="submit" name="btn_delete" id="btn_delete" value="Delete" /></td>
                        </tr>

and it works perfectly.

Am I missing something obvious?
By: Skrol29
Date: 2005-11-18
Time: 12:17

Re: Strange Behaviour With Alternating Rows

Hello Maz,

If you merge block "pending" before block "action" (the one for list box items), then you will have an unexpeted behavior because block "action" definition will be multiplied before its merging.
So just check that "action" is merged before "pending".

Otherwise your Html snippet looks ok.
Just a remark: only one "nodata" section is necessary. Other ones will be ignored. Even if you use alternative display.
By: Maz
Date: 2005-11-18
Time: 19:47

Re: Strange Behaviour With Alternating Rows

I double checked and that doesn't seem to be the problem. I should have pasted the calling code before hand I guess.

//-----------------------------------------
// Initialise template variables
//-----------------------------------------
$product_action     = array();

$product_action[]    = array('act' =>'Acknowledge Receipt',         'id'=>"1");
$product_action[]    = array('act' =>'Take for Testing',         'id'=>"2");
$product_action[]    = array('act' =>'Return as Faulty',         'id'=>"3");
$product_action[]    = array('act' =>'Return as Unsuitable',    'id'=>"4");

$pending_products     = $objStore->get_pending_products('1');

//-----------------------------------------
// Get pending products from DB
//-----------------------------------------
if($objStore->err_code)
{
    switch ($objStore->err_code)
    {
        case 1:
            $pending_products = array();
        break;
    }
}

$TBS->MergeBlock('action', $product_action);
$TBS->MergeBlock('pending', $pending_products);

$TBS->Show();

Thanks for the tip re the nodata! Any thoughts on what else could be causing the issue?
By: Maz
Date: 2005-11-18
Time: 20:05

Re: Strange Behaviour With Alternating Rows

Something that I have just noticed is that I have an XHTML warning as a result of the list ID:

line 57 column 8 - Warning: <select> anchor "product_state" already defined

I can't imagine that this has any bearing on the issue but thought I'd mention it just in case.
By: Skrol29
Date: 2005-11-20
Time: 14:14

Re: Strange Behaviour With Alternating Rows

Hello Maz,

I've reproduced your problem and I see what's going wrong.

You have two blocks named "action" (the blocks for the list box items).
When you merge this block, all what it between sections is deleted (there is no way to do differenlty). So you two "pending" sections become one.

To avoid this behavior, just simply rename the two blocks "action" into "action1" and "action2". Then replace your PHP code:
  $TBS->MergeBlock('action', $product_action);
with:
  $TBS->MergeBlock('action1,action2', $product_action);
By: Maz
Date: 2005-11-20
Time: 15:10

Re: Strange Behaviour With Alternating Rows

Thanks, Skrol but I'm not sure I fully understand.

Are you saying to change:

//-----------------------------------------
// Initialise template variables
//-----------------------------------------
$product_action     = array();

$product_action[]    = array('act' =>'Acknowledge Receipt',        'id'=>"1");
$product_action[]    = array('act' =>'Take for Testing',            'id'=>"2");
$product_action[]    = array('act' =>'Return as Faulty',            'id'=>"3");
$product_action[]    = array('act' =>'Return as Unsuitable',        'id'=>"4");

//-----------------------------------------
// Get pending products from DB
//-----------------------------------------
$pending_products     = $objStore->get_pending_products('1');

if($objStore->err_code)
{
    switch ($objStore->err_code)
    {
        case 1:
            $pending_products = array();
        break;
    }
}

$TBS->MergeBlock('action', $product_action);
$TBS->MergeBlock('pending', $pending_products);

to

//-----------------------------------------
// Initialise template variables
//-----------------------------------------
$product_action     = array();

$product_action[]    = array('act' =>'Acknowledge Receipt',        'id'=>"1");
$product_action[]    = array('act' =>'Take for Testing',            'id'=>"2");
$product_action[]    = array('act' =>'Return as Faulty',            'id'=>"3");
$product_action[]    = array('act' =>'Return as Unsuitable',        'id'=>"4");

//-----------------------------------------
// Get pending products from DB
//-----------------------------------------
$pending_products     = $objStore->get_pending_products('1');

if($objStore->err_code)
{
    switch ($objStore->err_code)
    {
        case 1:
            $pending_products = array();
        break;
    }
}

$TBS->MergeBlock('action1','action2','action3','action4' $product_action);
$TBS->MergeBlock('pending', $pending_products);

If so, how will this affect the building of the list in the template, as I currently have a nice and clean:

                            <select class="select" name="product_state" id="product_state[pending.product_id]">
                                <option value="[action.id]">[action.act;block=option;noerr]</option>
                            </select>

Confused from England. :)
By: Maz
Date: 2005-11-20
Time: 15:16

Re: Strange Behaviour With Alternating Rows

Ahhhhh!

I think I just figured what you meant... Like so, yes?

To Call:

$TBS->MergeBlock('action1,action2', $product_action);

Template:

                <table cellspacing="1" cellpadding="5" summary="List of products which are available for moderator preview">
                    <tr>
                        <th>Title</th>
                        <th>Author</th>
                        <th>Submitted</th>
                        <th>Category</th>
                        <th>Action</th>
                    </tr>
                    <tr>
                        <td class="light">[pending.product_title;noerr]</td>
                        <td class="light">[pending.name;noerr]</td>
                        <td class="light">[pending.product_date;frm='ddxx mmmm';noerr]</td>
                        <td class="light">[pending.cat_name;block=tr;noerr]</td>
                        <td class="light">
                            <select class="select" name="product_state" id="product_state[pending.product_id]">
                                <option value="[action1.id]">[action1.act;block=option;noerr]</option>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td class="dark" colspan="5">[pending;block=tr;nodata][lang.cell_no_results]</td>
                    </tr>
                    <tr>
                        <td class="dark">[pending.product_title]</td>
                        <td class="dark">[pending.name]</td>
                        <td class="dark">[pending.product_date;frm='ddxx mmmm']</td>
                        <td class="dark">[pending.cat_name;block=tr]</td>
                        <td class="dark">
                            <select class="select" name="product_state" id="product_state[pending.product_id]">
                                <option value="[action2.id]">[action2.act;block=option]</option>
                            </select>
                        </td>
                    </tr>
                </table>
By: Skrol29
Date: 2005-11-20
Time: 16:47

Re: Strange Behaviour With Alternating Rows

Yes, this last one should work
By: Maz
Date: 2005-11-20
Time: 20:57

Re: Strange Behaviour With Alternating Rows

Works great now.

Thanks again, Skrol.