Angular - FORM FORM FORM FOR CHANGE CHANGE
I am having problem changing json schema with angular schema form. If I set up the schema like in code, for example
$scope.schema = {
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Schema number ONE",
"type": "object",
"properties": {..
it works and displays the whole form as i want. But I want to load data from a web service.
So, I tried to set the schema to nothing and then change it by clicking a button, but it didn't work. I mean, I got the schema from the service, but the form doesn't change. For example, something like this in the 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": {
}
I want to select a schema to load and modify the form for the schema I have selected. Thank you very much.
source to share
As Claes pointed out in his comment, you need to trigger the schemaFormRedraw broadcast. However, when loading, the error comes from the validation on the schema you have like {}
it should 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');
}
source to share