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

fields disappearing on the form when using field.refresh #664

Open morgunder opened 6 years ago

morgunder commented 6 years ago

i have tried several things. i have tried just updating the url with the new value of the dependant. i just tried writing my own ajax layer. same thing.

issue: when i choose a different servicesubtype the ajax call gets made and the duration field disappears about 50% of the time and never comes back. makes it impossible to have chained fields on the form.

please help

var dsServiceSubTypes = function _dsServiceSubTypes(callback) {

  var value = this.observable("/company_id").get();

  $.getJSON(
    "/partner/select/servicesubtypes",
    {company_id: value},
    function(data) {
      callback(data);
    }
  );
  console.log('in _dsServiceSubTypes');

  // servicesubtype.options.dataSource = "/partner/select/servicesubtypes?company_id=" + company_id;

}

var dsDurations = function _dsDurations(callback) {

  var value = this.observable("/servicesubtype_id").get();

  $.getJSON(
    "/partner/select/durations",
    {servicesubtype_id: value},
    function(data) {
      console.log('in _dsDurations: ', value, data);
      callback(data);
    }
  );
  console.log('in _dsDurations');

  // duration.options.dataSource = "/partner/select/durations?servicesubtype_id=" + servicesubtype_id;

}

function _postRender(control) {
  var company        = control.childrenByPropertyId["company_id"];
  var servicesubtype = control.childrenByPropertyId["servicesubtype_id"];
  var duration       = control.childrenByPropertyId["duration_id"];

  servicesubtype.options.dataSource = dsServiceSubTypes;
  duration.options.dataSource = dsDurations;

  company.on("change", function() {
    // var company_id = company.getValue() | 0;

    servicesubtype.refresh();

  });

  servicesubtype.on("change", function() {
    // var servicesubtype_id = servicesubtype.getValue() | 0;

    duration.refresh();

  });

  // force change to happen on initial values - handled by x-depends-on
  company.trigger('change');
  servicesubtype.trigger('change');
}