Calling a genericForm from a genericMenu

I have been playing around with the following sample genericMenu example. I want to call a genericForm when the select button is pressed. However nothing happens. The menu keep functioning in a never ending loop.

var genericMenu = require('genericMenu');
var handler = {};
//This handler is called when any assigned softkeys/hardkeys are pressed
//It receives the id of the selected item and the action as parameters
handler.processMenuAction = function (params) {
	switch (params.actionId) {
	case 'select':
		selectCallback(params.selectionId);
		break;
	case 'exit':
		digium.background();
		break;
	}
};
//the menu items are defined in an array
var items = [
	{
		'text'  : 'Menu Entry 1',
		'id'    : 'item_1'
	},
	{
		'text'  : 'Menu Entry 2',	
		'id'    : 'item_2'
	},
	{
		'text'  : 'Menu Entry 3',
		'id'    : 'item_3'
	},
	{
		'text'  : 'Menu Entry 4',
		'id'    : 'item_4'
	}
];
//the softkeys are defined in an array
var softkeys = [
	{
		'label'		: 'Select',
		'actionId'	: 'select',
		'icon'		: app.images.softKeys.select
	},
	{
		'label'		: 'Cancel',
		'actionId'	: 'exit'
	}
];
//show the menu
genericMenu.show({
	'id'		: 'menu_1',
	'menu'		: items,
	'object'	: handler,
	'title'		: 'Menu Title',
	'softkeys'	: softkeys,
	'onkeyselect'	: selectCallback,
	'onkeycancel'	: digium.background
        'forceRedraw'	: true
});

function selectCallback(selection) {
    util.debug("Selected " + selection);
	};

I have tried calling my function for the form within the callback function as follows.

function selectCallback(selection) {
    util.debug("Selected " + selection);
    myForm();
	};

I have also tried adding a statement to stop observing the event as follows but all to no avail

function selectCallback(selection) {
    util.debug("Selected " + selection);
	digium.event.stopObserving({
	'eventName' : 'digium.app.foreground'
	});
	myForm();
	};

I have confirmed that the code within the form function is being executed. However teh menu remains on the screen and the keypress event keeps firing.

I tried running your sample to see the errors but it appears there was missing code.

Here is a modified version of your sample that shows a form when any one of the menu items is selected:

var genericMenu = require('genericMenu');
var genericForm = require('genericForm');
var util = require('util');
var app = require('app');
app.init();

var handler = {};
//This handler is called when any assigned softkeys/hardkeys are pressed
//It receives the id of the selected item and the action as parameters
handler.processMenuAction = function (params) {
    switch (params.actionId) {
        case 'select':
            selectCallback(params.selectionId);
            break;
        case 'exit':
            digium.background();
            break;
    }
};

//the menu items are defined in an array
var items = [
{
    'text'  : 'Menu Entry 1',
        'id'    : 'item_1'
},
{
    'text'  : 'Menu Entry 2',
    'id'    : 'item_2'
},
{
    'text'  : 'Menu Entry 3',
    'id'    : 'item_5'
},
{
    'text'  : 'Menu Entry 4',
    'id'    : 'item_4'
}
];

//the softkeys are defined in an array
var softkeys = [
{
    'label'      : 'Select',
    'actionId'   : 'select',
},
{
    'label'      : 'Cancel',
    'actionId'   : 'exit'
}
];

//show the menu
genericMenu.show({
        'id'      : 'menu_1',
        'menu'      : items,
        'object'   : handler,
        'title'      : 'Menu Title',
        'softkeys'   : softkeys,
        'onkeyselect'   : selectCallback,
        'onkeycancel'   : digium.background,
        'forceRedraw'   : true
        });

function selectCallback(selection) {
    util.debug("Selected " + selection);
    var form_items = [
        {
            'text'        : 'Extension number',
            'setting'     : 'extension',
            'inputType'   : 'numeric',
            'validate'    : '[0-9][0-9][0-9]',
            'errorMsg'    : 'Extension must be 3 digits in length',
            'inputParams' : {}
        },
        {
            'text'        : 'Password',
            'setting'     : 'password',
            'inputType'   : 'numeric',
            'validate'    : '[0-9]+',
            'errorMsg'    : 'Password must contain only digits',
            'inputParams' : {}
        }
    ];

    genericForm.show({
        'id'          : 'exampleForm',
        'labelWidth'  : (digium.phoneModel === 'D70') ? 140 : 125,
        'values' : {
            'extension' : '123',
            'password'  : ''
        },
        'inputs'      : form_items,
        'object'      : {
            processBack : function() {
                util.debug("Back pressed.");
                digium.background();
            },
            processSubmit : function() {
                util.debug("Submitted presssed.");
                for (var i = 0; i < form_items.length; i++) {
                    var setting = form_items[i].setting;
                    util.debug(setting + " : " + genericForm.getValue({'setting' : setting}));
                }
                digium.background();
            }
        },
        'title'       : 'Extension Login',
        'onkeyline1'  : digium.background,
        'onkeycancel' : digium.background,
        'forceRedraw' : true
    });
};

If you post a running version of your sample I could tell you what specifically was preventing the form from showing.

Thanks for your help. The main difference with your code is that you are putting the form code within the slectCallback function. I have confirmed that this works. However when I try and call another function from within selectCallback I get the same result, i.e., the function containing the form executes but the menu remains on the screen. However I’ll try and rework my code and structure it the way that you have.

I’ve tracked down my problem. The issue was in the form code. My generic.form.show method was wrapped i nan event as shown below. If I remove the event, as in your code, it fixes the problem.

digium.event.observe({ 'eventName' : 'digium.app.foreground', 'callback' : function () { genericForm.show({ 'id' : 'exampleForm', 'labelWidth' : (digium.phoneModel === 'D70') ? 140 : 125, 'values' : { 'test1' : '', 'test2' : '' }, 'inputs' : form_items, 'object' : { processBack : function() { util.debug("Back pressed."); digium.background(); }, processSubmit : function() { util.debug("Submitted presssed."); for (var i = 0; i < form_items.length; i++) { var setting = form_items[i].setting; util.debug(setting + " : " + genericForm.getValue({'setting' : setting})); } } }, 'title' : 'Form title', 'onkeyline1' : digium.background, 'onkeycancel' : digium.background, 'forceRedraw' : true }); } });

I’m not sure why this is the case. As I mentioned in my original post I suspected that this was the problem and had tried to stop observing the event using digium.event.stopObserving before calling my sub function. However the form seems to run OK without the event.

Many thanks for your help.