Skip to content

Form doesn't refresh when setting the schema and form to empty #806

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
s-anes opened this issue Nov 23, 2016 · 6 comments
Closed

Form doesn't refresh when setting the schema and form to empty #806

s-anes opened this issue Nov 23, 2016 · 6 comments

Comments

@s-anes
Copy link

s-anes commented Nov 23, 2016

Enhancement

As a developer, when I clear out the schema and the form an empty form should be rendered.

Expected behaviour

The following renders a text box:

$scope.form= [
  "name"
];

$scope.schema={
"type": "object",
  "properties": {
    "name": {
      "title": "Name",
      "type": "string"
    }
  }
};

If I then want to change the schema and the form to:

$scope.form= [];

$scope.schema={
"type": "object",
  "properties": {
  }
};

I expected the text box to disappear and the page to be empty.

Actual behaviour

It actually keeps displaying the text box despite the schema and the form being empty.

I've using angular.copy in both the schema and form and then redraw as per comments in #395, #428 but no joy:

$scope.form = angular.copy(newForm);
$scope.schema.properties = angular.copy(newSchema.properties);
$scope.$broadcast('schemaFormRedraw');

If the schema isn't empty (has anything in properties), the form clears if empty. The problem is I want to have a schema and a form per panel, and if a panel is empty (no questions) the schema shouldn't have any properties.

Have I done something wrong or am I missing something? I'd appreciate if anyone could shed some light here.

Thanks!

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

@Anthropic
Copy link
Member

@s-a-85 try this:

$scope.form = ["*"];
$scope.schema = {
  "type": "object",
  "properties": {
    "blank":{}
  }
};

It only bothers to render if there is something to render, so it needs something in properties.

@s-anes
Copy link
Author

s-anes commented Dec 1, 2016

Hi @Anthropic ,
Thanks for your reply. I had figured that out and even the following would do:

$scope.form = [];
$scope.schema = {
  "type": "object",
  "properties": {
    "blank":{}
  }
};

However, I would expect it to clear the form.
I assume there is no way to force it to 'bother'?
Thanks again.

@Anthropic
Copy link
Member

@s-a-85 well I would just watch the schema and form objects and if they were empty I would hide the entire form myself. But if you think it should clear both then I am happy to mark the issue as an enhancement request?

@SacSingh
Copy link

SacSingh commented Jan 9, 2017

I was having the same issue. Assigning the code below would not clear the pre-rendered form content.

$scope.Form = [];
$scope.Schema = []; 
$scope.$broadcast('schemaFormRedraw');

But now I've placed a conditional to check is $scope.From is empty and I'm calling the following code (provided by @Anthropic) to clear the previously rendered form.

$scope.form = [];
$scope.schema = {
  "type": "object",
  "properties": {
    "blank":{}
  }
};

@s-anes
Copy link
Author

s-anes commented Jan 10, 2017

@Anthropic Sorry for the late response. A work around is fine. Happy to close this issue.

@s-anes s-anes closed this as completed Jan 10, 2017
@Anthropic
Copy link
Member

@s-a-85 thank you for your time :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants