genericForm vs custom Group widget

Hi I’m not sure if I am doing something wrong, but, when I use a genericForm, when the user presses submit, I do a digium.background() to hide the form. After that looks like I need to do a window.clear, and then, add all controls that were present on my main window before I showed the generic form.

I’m wondering if I am doing things right because, the above technique causes lots of “flikering” on the screen. I am wondering if I am not better to simply use the group widget instead of a generic form, and using the visible property to show/hide it.

Any tips appreiciated

thanks in advance
wallnut

What I think I would recommend is not using digium.background(), but instead clear all the controls from the main window and then show your group that contains all the widgets you have set for your main screen.

So assuming you’ve setup group to have all your main window widgets you can do something like this in the processSubmit callback on the genericForm object parameter:

window.clear();
window.add(group);

Which will then just paint all your main window widgets back into the main window and there shouldn’t be any flickering.

A modified version of the genericFormExample showing this would be:

var util = require('util');
var app = require('app');
var screen = require('screen');
app.init();

var group = new Group(0, 0, window.w, window.h);
group.add(new Text(0,0,window.w, window.h, "This is the mock main window.\nPress any key to show the form again"));

var genericForm = require('genericForm');
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' : {}
    }
];

var form_params = {
    '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}));
            }
            window.clear();
            window.add(group);
        }
    },
    'title'       : 'Extension Login',
    'onkeyline1'  : digium.background,
    'onkeycancel' : digium.background,
    'forceRedraw' : true
};

digium.event.observe({
    'eventName' : 'digium.app.foreground',
    'callback'  : function () {
        genericForm.show(form_params);
    }
});

window.onkey = function(evt) {
        genericForm.show(form_params);
};

Does this work for you?

The flikering is gone thx, what I wanted to do was to do something like:

myform.visible = false;

to hide the form instead of putting the entire app in the background. I will look at your code more closely when I have a few mins, as I dont understand 100% (I’m slow sorry :wink:

thanks for the help

wallnut

Heh, no problem. Yeah, if you wanted to do something like that it might get complex since genericForm.show() removes all the existing widgets from the top level window. I think it would be easiest to keep using genericForm and just manage the widget group that is added to the top level window.