Ján Polaček
Ján Polaček

Reputation: 31

Angular-Schema-Form Change FORM on SCHEMA change

I have got a problem with changing json schema with angular schema form. If I set up schema like in code like this

$scope.schema = {
    "$schema": "http://json-schema.org/draft-04/schema#",
    "title": "Schema number ONE",
    "type": "object",
    "properties": {..

it works and renders whole form properly as I want. But I want to load data from web service.

So I tried to set up schema to nothing and then change it by clicking button, but it didnt work. I mean, i got schema from service, but form do not change. For example something like this in code.

$scope.schema = {};
$scope.changeSchema= function(){
    $scope.schema = {
        "$schema": "http://json-schema.org/draft-04/schema#",
        "title": "  Schema number two that I want",
        "type": "object",
        "properties": {
}

What I want is to select schema to load and change form to schema i selected. Thank you very much.

Upvotes: 3

Views: 1251

Answers (1)

Anthropic
Anthropic

Reputation: 701

As Claies pointed out in their comment, you need to trigger a schemaFormRedraw broadcast. However on load the error is due to validation on the schema that you have as {}, this would need to be a temporary schema, something along these lines should work:

$scope.schema = { "type": "object", "properties": {} }};
$scope.changeSchema = function() {
    $scope.schema = {
        "$schema": "http://json-schema.org/draft-04/schema#",
        "title": "  Schema number two that I want",
        "type": "object",
        "properties": {...}
    }
    $scope.$broadcast('schemaFormRedraw');
}

Upvotes: 1

Related Questions