PDA

View Full Version : access to button's 'value' option



DaveC426913
6 Aug 2010, 9:18 AM
Most of the buttons on my virtual keypad simply return the character that's on their face - when I press 'Q', it want to put 'Q' into my entryfield. But when I press 'SPACE', I want it to put ' ' into my entryfield.

The prefernce here is to have two properties on certain buttons: a text property, and an optional value property.

My button array:


defaults: {
xtype: 'button',
cls: 'key',
scope: this,
listeners : {
afterrender : function(){
this.mon(this.el, {
touchstart: me.touchStartHandler,
touchend: me.touchEndHandler
});
}
}
},
items: [ // kb1 keys
{ text: 'Q'},
{ text: 'W'},
etc. etc.
{ text: 'SPACE',
value: ' '},

My touch handler:


touchStartHandler: function(event){
var button = event.browserEvent;
if (button.value???){
textToAdd = button.value???;
}
else{
textToAdd = button.text;
}
},


As far as I can tell, the event object does not pass 'value'. Or if it does, I cannot find it.

Is there a way I can specify a property in my button array for these special buttons?

I'm going to need this for other control-type buttons as well, such as the backspace button. This is my plan:



{ xtype: 'button',
customAction: 'bksp',
}


then:


touchStartHandler: function(button, event){

if (button.customAction){
//this button has a custom action
switch (button.customAction){
case "bksp": //backspace
arr.pop();//pop last character off end
break;
}

DaveC426913
6 Aug 2010, 9:45 AM
Well, this works, but it' s kind of awkward:



{ text: 'SPACE',
badgeText:' ',
cls: 'key spckey'},

thisText = button.srcElement.innerText; // assume default
if (button.srcElement.parentElement.children.length>1){ //switch to badgeText if exists
thisText = button.srcElement.parentElement.children[1].innerText;
}


[EDIT]
This is more streamlined:


thisText = button.srcElement.parentElement.lastChild.innerText;

lastChild will normally be text, but badgeText will get tacked on if it exists.


Both of these solutions are surely dangerous practice. I wish I could refer to the elements explicitly rather than infer them by position. This code will muck up if in the future I add other properties.