Goto next record by "Enter" key

Hi all,

I have a single record form with a text edit box (not a database field) and other database fields.

I would like the users to input somethings into the text edit box and go to next record by pressing “Enter” key.

Can anyone show me how to do so ?

thanks,

Can anyone help me ?

I don’t know if there is an easier way or even a native option in ScriptCase to do such thing (well I haven’t found, at least), but you can achieve this functionality with JavaScript:

  1. Go to [Form Settings] > [JavaScript]
  2. “Select the object” = Form; “Select the event” = onLoad
  3. Click “Edit”
  4. Paste the following code and then click “Update”:

(function(){
    if(typeof window.sajax_do_call == "undefined" || typeof window.__original_sajax_do_call == "function"){
        return;
    }
    
    var ajaxStarted = false;
    var ajaxFinished = false;
    var uiBlocked = false;
    
    // intercept the ajax function to detect and change the 'ajaxStarted' flag
    window.__original_sajax_do_call = sajax_do_call;
    sajax_do_call = function(func_name, args){
        var result = __original_sajax_do_call(func_name, args);
        
        // only change the flag if its the form submission
        if((/^ajax_(.+)_submit_form$/i).test("ajax_form_categories_1_submit_form")){
            ajaxStarted = true;
        }
        
        return result;
    };
    
    $("form[name='F1']").on("keypress", "input", function(evt){
        if(evt.keyCode == 13){
            $(this).blur();
            
            // update data
            nm_atualiza("alterar");
            
            ajaxStarted = false;
            ajaxFinished = false;
            uiBlocked = false;
            
            var checkInterval = setInterval(function waitUntilSaveIsCompleted(){
                if(ajaxStarted && $(".blockUI").is(":visible")){
                    uiBlocked = true;
                }
                
                if(ajaxStarted && uiBlocked && !$(".blockUI").is(":visible")){
                    ajaxFinished = true;
                }
                
                if(ajaxFinished){
                    clearInterval(checkInterval);
                    
                    // go to next record
                    nm_move("avanca");
                }
            }, 30);
            
            evt.preventDefault();
            return false;
        }
    });
})();

  1. Generate and run the application to test

You can also use enable the option “Field with Initial Focus” ([Form Settings] > [Settings]) to put focus on a field after navigating through the records.

1 Like

Hi Mamede,

It is working fine.

One more thing, I would like to do a checking of the text box before the user can go to the next record.
If the checking fails, it would keep the user in the current correct.
On the other hand, if the checking passes, the user can go to the next record.

Any idea to do so ?

thanks,

Perhaps an other way to go:

Make a JavaScript Method:“next_record” with this code
nm_move(‘avanca’);

Make an ajax event “on change” related to your textbox and write the following code in the PHP editor of this event.
Image you want to check that there is content before go to the next record!?

If (!{<name of the textbox>} == “”){
sc_ajax_javascript(‘next_record’);
}

In the moment there is content and you TAB or ENTER (see your settings in the form) then it moves to the next record. (It loses the focus and the AJAX is fired)
If there is no content it does not move.
If you want to check something of the content then you should go the way to analyse the content with a script and a SQL like function.

That’s it…Have fun.

One question: Why do you want this? Not archiving the content in the database?

Regards Bert