EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: sectioni on April 09, 2017, 06:51:43 AM



Title: Cancelling a tab selection
Post by: sectioni on April 09, 2017, 06:51:43 AM
Hello,

I would like to do a 'confirm' dialog when switching tabs and only if OK i pressed, then the new tab should be selected and the 'onSelect' and 'onUnselect' events will be triggers.

I have not found a way of doing that...


Title: Re: Cancelling a tab selection
Post by: stworthy on April 10, 2017, 08:02:18 AM
Please attach the 'onBeforeOpen' event handler to each tab panels.
Code:
<script>
function onBeforeOpen(){
var opts = $(this).panel('options');
if (opts.canOpen == undefined){
opts.canOpen = false;
}
if (opts.canOpen){
return true;
}
$.messager.confirm('Confirm','Are you sure to select '+opts.title+'?', function(r){
if (r){
opts.canOpen = true;
$('#tt').tabs('select',opts.index);
opts.canOpen = false;
}
});
return false;
}
</script>
<div id="tt" class="easyui-tabs" style="width:700px;height:250px">
<div title="tab1" data-options="onBeforeOpen:onBeforeOpen"></div>
<div title="tab2" data-options="onBeforeOpen:onBeforeOpen"></div>
</div>


Title: Re: Cancelling a tab selection
Post by: sectioni on April 12, 2017, 03:45:49 AM
Works perfectly.