You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xap-commits@incubator.apache.org by mt...@apache.org on 2006/10/13 04:10:18 UTC
svn commit: r463557 - in /incubator/xap/trunk:
WebContent/examples/widgets/AttributeTester.js
WebContent/examples/widgets/textField.xal
src/xap/bridges/dojo/TextFieldBridge.js
Author: mturyn
Date: Thu Oct 12 21:10:17 2006
New Revision: 463557
URL: http://svn.apache.org/viewvc?view=rev&rev=463557
Log:
Bridge methods for onEdit and onTextChange seem o.k.---the example's handler for onTextChange falls down for non-alphabetic chars.
Modified:
incubator/xap/trunk/WebContent/examples/widgets/AttributeTester.js
incubator/xap/trunk/WebContent/examples/widgets/textField.xal
incubator/xap/trunk/src/xap/bridges/dojo/TextFieldBridge.js
Modified: incubator/xap/trunk/WebContent/examples/widgets/AttributeTester.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/WebContent/examples/widgets/AttributeTester.js?view=diff&rev=463557&r1=463556&r2=463557
==============================================================================
--- incubator/xap/trunk/WebContent/examples/widgets/AttributeTester.js (original)
+++ incubator/xap/trunk/WebContent/examples/widgets/AttributeTester.js Thu Oct 12 21:10:17 2006
@@ -21,6 +21,26 @@
alert(event);
}
+// Don't want to trigger an additional onEdit by popping up
+// an alert() box, which would make the textfield lose focus---so write it here
+AttributeTester.prototype.reportTextFieldEventWithoutAlert = function(event){
+ var sourceElement = event.source ;
+ var charCode = event.originalEvent.keyCode ;
+// if ( charCode < 65 || charCode>123 ){
+// return ;
+// }
+ if( ! event.originalEvent.shiftKey ){
+ charCode += 32 ;
+ }
+ var charr = String.fromCharCode(charCode);
+
+ sourceElement.setAttribute("text",""
+ //+ sourceElement.getAttribute("text")
+ + event.event+"[" + charr +"]; "
+ ) ;
+}
+
+
//IMPORTANT this works if you remove the same thing twice,
//no error. BEcause we still found element in hashtable?
AttributeTester.prototype.insertBefore = function( element ){
Modified: incubator/xap/trunk/WebContent/examples/widgets/textField.xal
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/WebContent/examples/widgets/textField.xal?view=diff&rev=463557&r1=463556&r2=463557
==============================================================================
--- incubator/xap/trunk/WebContent/examples/widgets/textField.xal (original)
+++ incubator/xap/trunk/WebContent/examples/widgets/textField.xal Thu Oct 12 21:10:17 2006
@@ -14,6 +14,7 @@
<xal:textField width="200px" text="123456789abcdef0" editable="true"
id="testComponent" onEdit="mco:attributeSetter.reportEvent(event)"
+ onTextChange="mco:attributeSetter.reportTextFieldEventWithoutAlert(event)"
/>
Modified: incubator/xap/trunk/src/xap/bridges/dojo/TextFieldBridge.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/bridges/dojo/TextFieldBridge.js?view=diff&rev=463557&r1=463556&r2=463557
==============================================================================
--- incubator/xap/trunk/src/xap/bridges/dojo/TextFieldBridge.js (original)
+++ incubator/xap/trunk/src/xap/bridges/dojo/TextFieldBridge.js Thu Oct 12 21:10:17 2006
@@ -50,6 +50,7 @@
//add listener last so we don't fire for the initial set
dojo.event.connect(this.getPeer(), "onblur",this,"onblur");
+ dojo.event.connect(this.getPeer(), "onkeyup",this,"onTextChange");
}
xap.bridges.dojo.TextFieldBridge.prototype.getPeerString = function(){
@@ -87,6 +88,35 @@
clientEvent.text = text;
this.fireEvent("onEdit",null,null,clientEvent);
}
+
+/**
+ * Fires an onTextChange() iff the field has lost focus
+ * and there has been a change in the text:
+**/
+xap.bridges.dojo.TextFieldBridge.prototype.onTextChange = function( kbdEvent ){
+ // Only do the rest if not read-only:
+ if( this.getPeer().isReadOnly() ){
+ return false;
+ }
+ var oldText = this.getElement().getAttribute(xap.xml.XmlTokens.TEXT) ;
+ var newText = this.getPeer().getText();
+
+ var clientEvent = new xap.session.ClientEvent(this.getElement(),this.getSession());
+
+ // fire an onTextChange() iff there's been a change:
+ if( oldText != newText ){
+ // I don't think we should change the element on
+ // every keystroke:
+ //this.writeBackAttribute(xap.xml.XmlTokens.TEXT,newText);
+ clientEvent.text = newText;
+ clientEvent.originalEvent = kbdEvent ;
+ this.fireEvent("onTextChange",null,null,clientEvent);
+ }
+ return false ;
+}
+
+
+
xap.bridges.dojo.TextFieldBridge.prototype.setMaxLengthAttribute = function( nMax ){