UnexposedWidgetMethods
From WebOS101
Unexposed Widget Methods
Consider the case of a TextField widget which is set up this way:
this.blargAttributes = {
hintText: 'blarg',
textFieldName: 'blarg',
enterSubmits: true,
holdToEdit: true, // you have to tap and hold it to edit this guy
multiline: false
};
this.blargModel = { value: 'blarg!!' };
this.controller.setupWidget('blarg', this.blargAttributes, this.blargModel);
Now, suppose there's some error condition for which you wish to focus on the widget. this.controller.get("blarg").focus() may seem reasonable, and indeed it would work for a TextField that doesn't have holdToEdit set. Arguably, you shouldn't be able to focus on this widget. It seems to be a bad UI decision, but I was determined to figure it out regardless. So I went source diving. And I found this business deep inside widget_textfield.js (used as an argument to Event.listen for a hold Event):
makeTextfieldEditable: function(event) {
var highlightTarget;
if (this.controller.attributes.holdToEdit) {
this.editable = true;
highlightTarget = Mojo.Gesture.highlightTarget;
if (highlightTarget) {
highlightTarget.removeClassName('selected');
}
this.updateEditableState(); //how can I get rid of selected before mouse up?
this.focus();
}
},
So it seems there is a method to do this. But it's not exposed. When you issue this.controller.get("blarg"), what you receive is the HTML DIV, not the widget object. There's literally no way to call makeTextfieldEditable() on the DIV that you're given. But the method does exist. Well, why does focus work then?
focus() works because it is exposed in widget_textfield.js (the exposeMethods function is in widget_controller.js):
this.controller.exposeMethods(['focus', 'blur', 'getValue', 'setText',
'setValue', 'getCursorPosition', 'setCursorPosition',
'setConsumesEnterKey']);
So, is there a way to get to makeTextfieldEditable() afterall? Indeed there is. Ultimately, to keep the widget object from getting garbage collected, it has to be stored somewhere. And the place they choose to keep it is in DIV["_mojoController"]. This is subject to change of course. That leading Hungarian Wart indicates that they (the Mojo devs) consider this private and possibly secret.
One more thing: the controller is responsible for setting up the widget, etc. The assistant has the actual methods. Anyway, here is the final result of my source diving. To give the holdToEdit TextField editable focus, do this:
$("blarg")._mojoController.assistant.makeTextfieldEditable();