PDA

View Full Version : How to attach listener to element to show window?



basememara
7 Feb 2012, 6:50 PM
I have an existing href link on my page. I am trying to attach a listener to the button so it shows the window when clicked. Below is what I have, which opens the window, but when I close the modal window and try to click to open it again, I get an error:

Uncaught TypeError: Cannot call method 'removeCls' of null

What am I doing wrong below?


<a id="window-button" href="#">Click here to launch window</a>
<div class="window-container" style="display: none">
<div id="sample">Window content goes here</div>
</div>



<script type="text/javascript"> Ext.application({
name: 'MyApp',
launch: function () {
var sampleWindow = Ext.create('Ext.window.Window', {
title: 'Sample',
height: 600,
width: 600,
modal: true,
autoScroll: true,
contentEl: 'sample'
});


Ext.get('window-button').on('click', function () {
sampleWindow.show();
});
}
});
</script>

Also is there an easier way to just put the element id in the window config just like contentEl?

vietits
7 Feb 2012, 7:42 PM
It's because when you click the close button, it will be default to destroy the window so you can't show it again. To hide instead of destroy window, let set closeAction config to 'hide' when you create window.