Save form state?

Save form state?

timwoolleytimwoolley Posts: 10Questions: 3Answers: 0

Hello,

I was just curious if there is a method available that will save the current state of the form?

I would like to save the current state of the form (i.e. any sort of user input to form fields) and then apply that state back to the form at a later time.

Thanks!

Answers

  • timwoolleytimwoolley Posts: 10Questions: 3Answers: 0

    I think I found one way to solve this.

    .on('preSubmit', function(event, data, action) {
        saved_form_state = data.data;
        ...
    

    Later:

    $.each(saved_form_state, function(name, val) {
        that.val(name, val);
    });
    

    Looks like Editor makes it easy when compared to a more jQuery-centric way of updating various form field types. From what I can tell, the .val(<field-name>, <value>) method handles the nitty gritty for when it comes to radio buttons vs. checkboxes, vs. selects, vs inputs, etc.

    Cool!

  • timwoolleytimwoolley Posts: 10Questions: 3Answers: 0

    Shoot, I just realized that using that.val(name, val); makes "undo" buttons appear. Then, when I click "undo" I get multi-vals (looks like the editor thinks I want to edit multiple values, rather than just replacing the value that's there).

    Hrmm, back to drawing board.

  • timwoolleytimwoolley Posts: 10Questions: 3Answers: 0

    So, I ended up re-working my code and ended up finding another solution that does not need me to save user form state. This solves the multiple values issue. My new approach, for what I'm trying to do, is much better anyway. Thanks for reading.

This discussion has been closed.