5

I create my alpaca form with the following syntax:

function createNewAlpacaForm(data, schema, formId, saveButtonId, clickEventFunc) {
    $(formId).empty();
    $(saveButtonId).off('click');
    alpacaForm = $(formId).alpaca({
        "data" : data,
        "schema" : schema,
        "view" : "VIEW_BOOTSTRAP_EDIT",
        "postRender" : function(renderedForm) {
            clickEventFunc(renderedForm);
        }
    });
}

This works great, but I now want to update the data dynamically. I have a restore to default button which take my default JSON data and apply it to the form. I take care of this now by completely re-creating the form with the default JSON but this is clunky as the form flickers as it re-creates. Any ideas how to update the JSON data dynamically without re-creating the entire alpaca form?

Jacob van Lingen
  • 8,989
  • 7
  • 48
  • 78
Michael LoCicero
  • 423
  • 1
  • 5
  • 11
  • Why arew you using $(saveButtonId).off('click'); – Jain Jun 10 '14 at 17:00
  • I have a select box with an ID which generates different alpaca forms on select. Each form uses the same saveButton(i.e. button input). I pass the button inputs on click event function to the createNewAlpacaForm which is used in the postRender callback. I need to clear the buttons on click event function mapping each time before setting it again in this createNewAlpacaForm function. – Michael LoCicero Jun 10 '14 at 20:19
  • Does not really pertain to my question, but I answered anyway :) – Michael LoCicero Jun 10 '14 at 20:20

1 Answers1

7

You can dynamically get the Alpaca form and setValue() similarly to how you use getValue() to retrieve the form values. I think this would work in your case:

$(formId).alpaca('get').setValue(data);
Jon
  • 81
  • 1
  • 6