Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

alpaca javascript dom update

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?

like image 594
Michael LoCicero Avatar asked Jun 10 '14 16:06

Michael LoCicero


1 Answers

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);
like image 92
Jon Avatar answered Oct 14 '22 00:10

Jon