PDA

View Full Version : Graceful degradation?



mirage
27 Apr 2007, 6:46 AM
Hi -

I'm just starting with ExtJS. I'm using the release version.

My problem is probably something really simple and I feel stupid for asking. But I've tried and can't seem to figure it out. I [try to] code my markup so that it gracefully degrades with incompatible browsers or where JavaScript isn't available.

In my HTML I invoke a BasicDialog from a link:


<a title="Click to view errors" id="showerrors-link" href="/item/showerrors">View Errors</a>

I then hook up the BasicDialog example to that element:


showBtn = Ext.get('showerrors-link');
// attach to click event
showBtn.on('click', this.showDialog, this);


I want to return false from the click event as to not have the href execute. My best guess was to modify the event like this:


showBtn.on('click', function() {this.showDialog(); return false;}; this);


But it's not doing what I want. The only way to get it to work is by putting a literal onclick event in the HTML:


<a title="Click to view errors" id="showerrors-link" href="#" onclick="return false;">View Errors</a>

I had kind of stopped adding event attributes to the markup so it feels backwards to me. What's my alternative?

Thanks,
Juergen

cklester
27 Apr 2007, 7:39 AM
You'll need to use the preventDefault() thingie:

.on('click', function(e) { e.preventDefault(); this.showDialog(); } );

On a side note, it's not really graceful degradation as much as it is progressive enhancement.

mirage
27 Apr 2007, 10:11 AM
You'll need to use the preventDefault() thingie:

.on('click', function(e) { e.preventDefault(); this.showDialog(); } );

On a side note, it's not really graceful degradation as much as it is progressive enhancement.

Now that you say it, I can see it too. The glass is half-full!:D

Thanks for the help. Much appreciated and exactly what I was looking for.

Juergen