I'm having trouble with field modification after entering a number outside the range specified with set_field_type() : the cursor stays in the field but I'm unable to enter any valid number after that. Any further digits entered seems to be ignored.

I'm using a sample demo found on internet (text), panel_browse, 3 windows, 3 panels and cycling through them with tab key) and adding a form in the third panel (and obviously in the third window)

I'm printing results depending on the fields values in the second panel to not interfere with the form (I first wanted to mix the form and the results printed all in the second panel but it was a mess, cursor could not go in the field properly)

I choose to skip fields automatically, so "field_opts_off(field[0], O_AUTOSKIP);" are commented out.

As long as I type numbers in the range specified, no issue.

But soon as I type a number out of that range, I'm stuck in the field and I'm unable to modify it and unable to skip to another field as well...

That's obviously and most probably a form field validation issue but I didn't find anything to help me. I thought this was something automatically handled by ncurses but I'm thinking it is not but I can't find how to remedy to that.

What happens if field validation doesn't pass ? Anything to check with some function ? If yes, which one ? Do I have to define one ? ncurses official documentation is not very helpful.


WINDOW *my_wins[3];
PANEL *my_panels[3];
PANEL *top;
int ch, rows, cols;
FORM *my_form;
.
.
.
FIELD *field[4];
.
.
.
field[0] = new_field(1, 2, 0, 0, 0, 0);
field[1] = new_field(1, 2, 0, 4, 0, 0);
field[2] = new_field(1, 2, 0, 8, 0, 0);
field[3] = NULL;

set_field_type(field[0], TYPE_INTEGER, 2, 0, 23);
set_field_type(field[1], TYPE_INTEGER, 2, 0, 59);
set_field_type(field[2], TYPE_INTEGER, 2, 0, 59);

set_field_back(field[0], A_UNDERLINE);
set_field_back(field[1], A_UNDERLINE);
set_field_back(field[2], A_UNDERLINE);

my_form = new_form(field);
scale_form(my_form, &rows, &cols);
set_form_win(my_form, my_wins[2]);
set_form_sub(my_form, derwin(my_wins[2], rows, cols, 5, 45));
post_form(my_form);
.
.
.
while ((ch = getch()) != KEY_EXIT /*KEY_F(1) */ && (ch != 27))
    {
    switch (ch)
    {
    case KEY_RIGHT:
        form_driver(my_form, REQ_NEXT_FIELD);
        form_driver(my_form, REQ_END_LINE);
        break;
    case KEY_LEFT:
        /* Go to previous field */
        form_driver(my_form, REQ_PREV_FIELD);
        form_driver(my_form, REQ_END_LINE);
        break;
    case 9:
        top = (PANEL *)panel_userptr(top);
        top_panel(top);
        break;
    
    default:
        if (top == my_panels[2])
        {
         form_driver(my_form, ch);
        }
        break;
        }
    }end switch

.
.
.
// some processing depending on fields value and printing in second panel
.
.
.
refresh();
update_panels();
doupdate();
}//end while

I tried to force a driver_form(my_form, REQ_VALIDATION) on each digit entered but that doesn't change anything, and maybe it's even worse...

0

There are 0 best solutions below