gitana / alpaca

Alpaca provides the easiest way to generate interactive HTML5 forms for web and mobile applications. It uses JSON Schema and simple Handlebars templates to generate great looking, dynamic user interfaces on top of Twitter Bootstrap, jQuery UI, jQuery Mobile and HTML5.
http://www.alpacajs.org
Other
1.29k stars 371 forks source link

Changing data in javascript #666

Open wlambrechts2 opened 6 years ago

wlambrechts2 commented 6 years ago

Hi,

Just started with Alpaca. Seems great but I can't seem to manage to change the data in Jquery. I only succeed in assigning a variable to the data and then change the value of the data variable and destroy and recreating the Alpaca form (which causes flickering).

I found the answer to this question: https://github.com/gitana/alpaca/issues/508 but the answer does not seem to work. It just does nothing.

Thanks

pkeogan commented 6 years ago

Here is a snippet of my code.

functions is for editing models, but you can see the code to set the data $("#{{$id}}").alpaca().setValue(data);

setValue is what your looking for.

   jQuery.fn.extend({
        editModel: function (id) {
          $.ajax({
            type: "GET",
            url: "{{ $dataRoute }}/" + id,
            success: function(data) {
              lastAlpacaJson = data;
              lastAlpacaModelID = id;
              $("#{{$id}}").alpaca().setValue(data);
              $("#{{$id}}-modal").modal('show');  
            },
            error: function(XMLHttpRequest, textStatus, errorThrown) {
              swal('Error', XMLHttpRequest.responseJSON.message ,'error');
            },
          });
        }
    });
wlambrechts2 commented 6 years ago

Thanks !

pkeogan commented 6 years ago

let me know if you need anymore help.

I made some jquery to be able to load more remote data, and postRender functions.