0

I'd like to make a question <form> with autosaving similar to this one on Stackoverflow. I understand that unobtrusive autosaving can we done with setInterval() and $.ajax() (ref.1 ref.2) but I'm more interested in the form validation Stackoverflow uses to determine whether or not the form submits after a given interval of time.

My question is, should I just keep the validation simple and make sure the user has inputed, say more than 5 characters (or that more than 5 characters have changed)? What else should I be thinking about for the form validation specifically in the case of autosaving (or in contrast with user-initiated submit()).

Community
  • 1
  • 1
tim peterson
  • 23,653
  • 59
  • 177
  • 299
  • 1
    You can just save the user inputs no matter its validation; also, it can be saved in client-side, such as `localStorage`, instead of server-side. – Haocheng Dec 01 '12 at 13:33
  • @Haocheng, thanks but it is necessary for me to have validation and to submit server-side – tim peterson Dec 01 '12 at 13:38

2 Answers2

1

You can keep it simple by updating user's input after few seconds of last key strokes.

This is what a jquery code my looks like.

var timer = null;
$(inputElem).on('keyup',function(){
    clearTimeout(timer);

    // Update user input after 5 seconds of last keystroke
    timer = setTimeout( updateUserInput , 5 * 1000 ); 
});

And important thing to take in consideration is keeping track of revisions. In case user may not want to keep it's current changes, then it should be able to revert back to last copy.

Still all these things depends on the type of app you want to develop.

Vinay Aggarwal
  • 1,565
  • 1
  • 10
  • 19
0

this example for test if user change or add/remove 5 characters or not

by testDeff function

http://jsfiddle.net/alaa13212/PSJ4z/

alaa
  • 11
  • 2
  • This test only works if nothing is in the textbox to begin with. Can you modify it to **also** account for checking whether some existing input value is modified by 5 characters? – tim peterson Dec 01 '12 at 15:17
  • i'm sorry, use 5 instead of 3. – alaa Dec 02 '12 at 11:18