PDA

View Full Version : Messagebox on links



Dextro
3 Aug 2007, 1:20 AM
This is a simple question, but somehow I can't figure out how to get this to work.

I have a Messagebox and several links. How can I stop the link to follow its target (href) until there is clicked on the OK button?



Ext.onReady(function(){

Ext.select('a.confirmDelete').on('click', function(e, target, options){
Ext.Msg.show({
title: 'Delete this item?',
msg: 'description',
buttons: Ext.MessageBox.OKCANCEL
});

return false;
});

});


Apparently the 'return false;' doesn't work.

Dextro
3 Aug 2007, 2:21 AM
Apparently this is not possible.

More information: http://extjs.com/forum/showthread.php?t=6808

fay
3 Aug 2007, 2:45 AM
I'm not sure if I completely understand you, but try taking a look at http://extjs.com/deploy/ext/docs/output/Ext.MessageBox.html

Perhaps make the href in your confirmDelete link blank, and use the fn handler to do any processing after a button has been clicked in the MessageBox.


Ext.onReady(function(){

Ext.select('a.confirmDelete').on('click', function(e, target, options){
Ext.Msg.show({
title: 'Delete this item?',
msg: 'description',
buttons: Ext.MessageBox.OKCANCEL,
modal: true;
fn: function(btn){
if (btn == 'ok'){
//... delete, etc.
}
}
});
return false;
});
});

Dextro
3 Aug 2007, 3:08 AM
That's exactly what I'm doing now. The problem is that there are a lot of parameters in my url in the href that I have to pass through my function to create a correct redirect.

It was much easier if the messagebox acted like a normal alertbox, but skinnable. But this is not possible.

mystix
3 Aug 2007, 4:56 AM
why not store those href params in a custom attribute?

e.g.


<a href="javascript:void(0);" custom_href="http://my/link?bla=bla&foo=bar">my link</a>

Dextro
3 Aug 2007, 5:12 AM
That's a good idea mystix, but the XHTML-code isn't valid then.

fay
3 Aug 2007, 6:22 AM
This mightn't be exactly what you are looking for but...


<script>
function ConfirmDelete(href)
{
Ext.Msg.show({
title: 'Delete this item?',
msg: 'description',
buttons: Ext.MessageBox.OKCANCEL,
fn: function(btn){
if (btn == 'ok')
window.location.href = href;
}
});
}

Ext.onReady(function(){
var nodes = Ext.select('a.confirmDelete');
for (var i = 0; i < nodes.elements.length; i++)
{
var node = nodes.elements[i];
node.href = 'javascript:ConfirmDelete("' + node.href + '");';
}
});
</script>

<body>
<a class="confirmDelete" href="http://www.google.com">google</a><br />
<a class="confirmDelete" href="http://www.yahoo.com">yahoo</a>
</body>