jquery - alpaca javascript dom update - Stack Overflow

I create my alpaca form with the following syntax:function createNewAlpacaForm(data, schema, formId, sa

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 pletely 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?

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 pletely 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?

Share Improve this question edited Aug 10, 2015 at 13:01 Jacob van Lingen 9,5977 gold badges54 silver badges83 bronze badges asked Jun 10, 2014 at 16:52 Michael LoCiceroMichael LoCicero 4431 gold badge6 silver badges12 bronze badges 3
  • Why arew you using $(saveButtonId).off('click'); – Jain Commented Jun 10, 2014 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 Commented Jun 10, 2014 at 20:19
  • Does not really pertain to my question, but I answered anyway :) – Michael LoCicero Commented Jun 10, 2014 at 20:20
Add a ment  | 

1 Answer 1

Reset to default 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);

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744965122a4603629.html

相关推荐

  • jquery - alpaca javascript dom update - Stack Overflow

    I create my alpaca form with the following syntax:function createNewAlpacaForm(data, schema, formId, sa

    1天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信