Automatic saving

Does anyone knows how to do an automatic save on a form when navigating from record to records ?
I just don’t want my user to click the save button and after that, click the next button.

Thanks

Sylvain

[QUOTE=sdanigo;36175]Does anyone knows how to do an automatic save on a form when navigating from record to records ?
I just don’t want my user to click the save button and after that, click the next button.

Thanks

Sylvain[/QUOTE]

If you have a logical flow of forms then set a sc_redir in the onafterinsert button. Don’t forget to start the procedure with a sc_commit_trans(); Then after save you will jump to the next form automatically.

Hi,
well, my form display record by record some data.
These data are pre-populated, so my form is not in insert mode, but always in edit mode (you can only change value in the form, not add a new record).
I navigate between records using the buttons in the tool bar (prev, next,…).
My goal is to save the form just before leaving it when a user click the next button for instance (I don’t want him to have to click the save button then the next button).
Is there a way to do that ?

Thanks

Sylvain

the only solution would be to use an ajax onchange event with an update sentence… but i have to tell you that your application performance will decrease a lot

Hi,
I’m quite sure it could be easy.

I can use that piece of code to update the whole form

// Javascript function parameters
$javascript_function = ‘nm_atualiza’;
$javascript_parameters = array( ‘alterar’);
// Call javascript function
sc_ajax_javascript($javascript_function, $javascript_parameters);

I’ve tried to put that in some events (onNavigate for instance) but it doesn’t work (I think that the onNavigate is triggered to late, we have already quit the form).

If someone has an idea, it would be greatly appreciated.

Thanks

Sylvain

The best would be to create your own javascript buttons (first_rec,prev_rec,next_rec, last_rec).

Button code (next_rec):


nm_atualiza('alterar');
setTimeout(function() {nm_move('avanca');},1000); //you need a delay (1000 = 1s) here to wait for the update to finish, otherwise the form would lock up. You might need to adjust the time. Just try what works best for your system.

Parameters for nm_move():
first = ‘inicio’
previous = ‘retorna’
next = ‘avanca’
last = ‘final’

jsb

Hi,
thanks,
that works perfectly :slight_smile:

yes, it works for me as well.
the problem is that form save will be done on any navigation even if nothing has changed.
here is an improvement:

  1. by any change of an element it will add a class to this element
  2. by navigating it will save the record and move according to the button script
  3. by leaving/closing the form unsaved it will warn the user.

// code for a button (next , prev , etc) if ($(’.changed-input’).length) {

//console.log (“changes where made, saving”);
$(".changed-input").removeClass(“changed-input”);
nm_atualiza(‘alterar’);
setTimeout(function() {nm_move(‘avanca’); },500);

//return ‘You haven’t saved your changes.’;
}
nm_move(‘avanca’);

code for onLoad event

?>

<script>

$( document ).ready(function() {
console.log( “ready!” );

$(’#putyourformidherebyusinginspectelementfinditin crome).on(‘change keyup keydown’, ‘input, textarea, select’, function (e) {
$(this).addClass(‘changed-input’);
console.log(this.name + " has changed");

});

$(window).on(‘beforeunload’, function () {
return “Some changes were not saved.”;
});

});

</script>

<?php