json-schema-form / angular-schema-form

Generate forms from a JSON schema, with AngularJS!
https://json-schema-form.github.io/angular-schema-form
MIT License
2.47k stars 653 forks source link

How do I prevent the form from refreshing on schemaFormRedraw #922

Open GenyaB opened 7 years ago

GenyaB commented 7 years ago

I am using $scope.$broadcast('schemaFormRedraw'); after dynamically adding elements to my angular-schema-form, however, when I do this, it refreshes the form and reverts back to the first tab every time.

I've had a look at the render() and internalRender() functions inside the schema-form.js and have a feeling it's something in those two functions.

Here is how I am adding the elements:

//declaring the form and schema on enter

 $scope.$on("$ionicView.enter", function(event, data) {
      $scope.schema = {
        type: "object",
        properties: {

        }
      };

       $scope.form = [
        "name",
        {
          type: "tabs",
          tabs: [
          ]
        }
      ];

    });

//adding tabs
$scope.tabAdd = function(tabName){
  console.log($scope.form[1].tabs.length);
  if($scope.form[1].tabs.length == 0){
    $scope.state = 0;
  }
  else{
    $scope.state = $scope.state +1;
  }
  console.log($scope.state);
  var tab = {
        title: tabName,
        tabType: "top",
        items: []
      }

  $scope.form[1].tabs.push(tab)

//this prevents the updateOn error that I get without it
  $scope.$broadcast('schemaFormRedraw');
};

@json-schema-form/angular-schema-form-lead

Anthropic commented 7 years ago

@GenyaB the schema and form are compiled into an Intermediate Representation which is then used for the display, updating the schema or form then regenerates the IR which causes the form to regenerate display. I have been wanting to find time to create a tab add-on that allows defining a schema/form to dsiplay as the content of the tab, but keep running out of time.

GenyaB commented 7 years ago

@Anthropic Ah I see, I've been playing around as well but no luck. Let me know if you come up with a working solution.