jbraband
20 Feb 2007, 3:01 PM
I have a seemingly simple issue, but can make heads or tales of it.
i have a bunch of form elements within the tab of a BasicDialog element. Think of the dialog element as a form and when closing the box (via provided button), i want to prompt the user to save their changes; but only if they have indeed made changes.
So I am keeping an _isSaved variable (a dirty flag) with applicable mutators and accessors and assigned a function to the 'change' event of the form elements that set the _isSaved variable to false.
The issue I'm running into is when I click on an input box, change the text, and then click the button...without first removing focus from the input box. The 'click' event of the button fires before the 'change' event of the input box. in fact, the 'change' event never fires until i change focus.
is there another approach/event that I can use besides 'change'?
also, can someone describe the differences between on and mon (event listeners vs. managed listeners)?
here is a sample page that demonstrates the above senario (of course, change the pathing to yui-ext, yui, etc...)
<html>
<head>
<title>Test Page</title>
<script type="text/javascript" src="../Resources/yui/utilities/utilities.js"></script>
<script type="text/javascript" src="../Resources/yui-ext/yui-ext-debug.js"></script>
<link rel="stylesheet" type="text/css" href="../Resources/yui-ext/resources/css/examples.css" />
<link rel="stylesheet" type="text/css" href="../Resources/yui-ext/resources/css/tree.css" />
<link rel="stylesheet" type="text/css" href="../Resources/yui-ext/resources/css/yui-ext.css" />
</head>
<body>
<div id="Dialog">
<div class="ydlg-hd">Test Box</div>
<div class="ydlg-tab" title="Test Tab">
<div class="inner-tab">
<input type="text" id="InputBox" value="Default Value" />
</div>
</div>
</div>
<script language="javascript" type="text/javascript">
var d = new YAHOO.ext.BasicDialog("Dialog", { modal:true,
autoTabs:true,
width:200,
height:200,
shadow:true,
proxyDrag: false,
draggable: false,
resizable: false,
closable: false});
d.addButton('Test Button', function () { alert('Button Click'); } );
d.show();
var input = getEl('InputBox');
input.on('change', function () { alert('Input Changed'); });
</script>
</body>
</html>
i have a bunch of form elements within the tab of a BasicDialog element. Think of the dialog element as a form and when closing the box (via provided button), i want to prompt the user to save their changes; but only if they have indeed made changes.
So I am keeping an _isSaved variable (a dirty flag) with applicable mutators and accessors and assigned a function to the 'change' event of the form elements that set the _isSaved variable to false.
The issue I'm running into is when I click on an input box, change the text, and then click the button...without first removing focus from the input box. The 'click' event of the button fires before the 'change' event of the input box. in fact, the 'change' event never fires until i change focus.
is there another approach/event that I can use besides 'change'?
also, can someone describe the differences between on and mon (event listeners vs. managed listeners)?
here is a sample page that demonstrates the above senario (of course, change the pathing to yui-ext, yui, etc...)
<html>
<head>
<title>Test Page</title>
<script type="text/javascript" src="../Resources/yui/utilities/utilities.js"></script>
<script type="text/javascript" src="../Resources/yui-ext/yui-ext-debug.js"></script>
<link rel="stylesheet" type="text/css" href="../Resources/yui-ext/resources/css/examples.css" />
<link rel="stylesheet" type="text/css" href="../Resources/yui-ext/resources/css/tree.css" />
<link rel="stylesheet" type="text/css" href="../Resources/yui-ext/resources/css/yui-ext.css" />
</head>
<body>
<div id="Dialog">
<div class="ydlg-hd">Test Box</div>
<div class="ydlg-tab" title="Test Tab">
<div class="inner-tab">
<input type="text" id="InputBox" value="Default Value" />
</div>
</div>
</div>
<script language="javascript" type="text/javascript">
var d = new YAHOO.ext.BasicDialog("Dialog", { modal:true,
autoTabs:true,
width:200,
height:200,
shadow:true,
proxyDrag: false,
draggable: false,
resizable: false,
closable: false});
d.addButton('Test Button', function () { alert('Button Click'); } );
d.show();
var input = getEl('InputBox');
input.on('change', function () { alert('Input Changed'); });
</script>
</body>
</html>