More on the JavaScript bug I had - and how it relates to Spry

So, a few hours ago I posted about an odd JavaScript issue I was having where I couldn’t set a field’s disabled property. Turns out it was an issue with Spry, and one that makes sense if you think of it. My code was doing something like so:

if(offset == 0) $("prevbutton").disabled=true; else $("prevbutton").disabled=false;

if((offset + pageSize) >= numRows) $(“nextbutton”).disabled=true; else $(“nextbutton”).disabled=false;

Spry.Data.updateRegion(“issues”); </code>

This code was run anytime you would click the Previous or Next buttons. It was a basic page handler for my dataset. The updateRegion call basically redrew the region. I had code inside it to check and see if a row should be displayed:

<tr spry:repeat="dsIssues" spry:even="adminList0" spry:odd="adminList1" spry:test="{ds_RowNumber} >= pageOffset && {ds_RowNumber} < pageStop">

The problem came up due to the fact that I had this inside the region:

<input type="button" id="prevbutton" value="Prev" onclick="UpdatePage(pageOffset - pageSize);" disabled="true">

I had the previous button disabled at first since, obviously, you start on the first page. However, when I ran the updateRegion command, Spry essentially “reloaded” my initial HTML, which means the disabled=true was also being rerun.

Obvious. But of course - most bugs are (after you fix them).

Raymond Camden's Picture

About Raymond Camden

Raymond is a developer advocate for Extend by Auth0. He focuses on serverless and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support.

Lafayette, LA https://www.raymondcamden.com

Comments