Skip to content

Onchange update the Schema not working #428

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
senthilsendhil opened this issue Jun 12, 2015 · 4 comments
Closed

Onchange update the Schema not working #428

senthilsendhil opened this issue Jun 12, 2015 · 4 comments

Comments

@senthilsendhil
Copy link

I like to update my schema after Form loader through onChange,

but schema not getting updated, Please refer the below controller code.

 $scope.testOnchange = function() {
    console.log('came here');
    $scope.schema.properties.profileDetails.properties.address.properties.
    addressDetails.items.properties.addressFormat = ['dym', 'dym1'];
    $scope.$broadcast('schemaFormRedraw');

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

        "type": "object",
        "properties": {
          "address": {
            "type": "object",
            "properties": {
              "addressDetails": {
                "title": "Contact Person",
                "type": "array",
                "minItems": 1,
                "items": {
                  "type": "object",
                  "properties": {
                    "addressType": {
                      "title": "Contact Type",
                      "description": "Select",

                      "type": "string",
                      "default": "test",
                      "enum": ["test", "test1"]
                    },
                    "addressFormat": {
                      "title": "Address Format",
                      "description": "Select",
                      "type": "string",
                      "default": "test",
                      "enum": []
                    }
                  }
                }
              }
            }
          }
        }
      }

    }
  };


  $scope.form = [{
      "key": "profileDetails.address.addressDetails",
      "title": "The array",
      "type": "array",
      "items": [{
          "key": "profileDetails.address.addressDetails[].addressType",
          "onChange": "testOnchange()"
        }, {
          "key": "profileDetails.address.addressDetails[].addressFormat",

        }



      ]
    }, {
      "type": "submit",
      "style": "btn-info",
      "title": "OK"
    }

  ];
@davidlgj
Copy link
Contributor

So you've hit this bug: #395

Try doing an angular copy of the form definition whenever you update the schema, something like:

$scope.testOnchange = function() {
    console.log('came here');
    $scope.schema.properties.profileDetails.properties.address.properties.
    addressDetails.items.properties.addressFormat = ['dym', 'dym1'];
    $scop.form = angular.copy($scope.originalForm);
    $scope.$broadcast('schemaFormRedraw');

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

        "type": "object",
        "properties": {
          "address": {
            "type": "object",
            "properties": {
              "addressDetails": {
                "title": "Contact Person",
                "type": "array",
                "minItems": 1,
                "items": {
                  "type": "object",
                  "properties": {
                    "addressType": {
                      "title": "Contact Type",
                      "description": "Select",

                      "type": "string",
                      "default": "test",
                      "enum": ["test", "test1"]
                    },
                    "addressFormat": {
                      "title": "Address Format",
                      "description": "Select",
                      "type": "string",
                      "default": "test",
                      "enum": []
                    }
                  }
                }
              }
            }
          }
        }
      }

    }
  };


  $scope.originalForm = [{
      "key": "profileDetails.address.addressDetails",
      "title": "The array",
      "type": "array",
      "items": [{
          "key": "profileDetails.address.addressDetails[].addressType",
          "onChange": "testOnchange()"
        }, {
          "key": "profileDetails.address.addressDetails[].addressFormat",

        }
      ]
    }, {
      "type": "submit",
      "style": "btn-info",
      "title": "OK"
    }

  ];
  $scop.form = angular.copy($scope.originalForm);

@senthilsendhil
Copy link
Author

@davidlgj below error I am getting after Copy $scop.form = angular.copy($scope.originalForm);

Uncaught Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
Watchers fired in the last 5 iterations: [[{"msg":"schemaForm.form[0]","newVal":{"title":"profileDetails","schema":{"type":"object","properties":{"address":{"type":"object","properties":{"addressDetails":{"title":"Contact Person","type":"array","minItems":1,"items":{"type":"object","properties":{"addressType":{"title":"Contact Type","description":"Select","type":"string","default":"test","enum":["test","test1"]},"addressFormat":["dym","dym1"]}}}}}}},"ngModelOptions":{},"type":"fieldset","items":[{"title":"address","schema":"<>","ngModelOptions":{},"type":"fieldset","items":[{"title":"Contact Person","schema":"<>","ngModelOptions":{},"type":"array","key":["profileDetails","address","addressDetails"],"items":[{"title":"addressDetails","schema":"<>","ngModelOptions":{},"type":"fieldset","items":[{"title":"Contact Type","description":"Select","schema":"<>","ngModelOptions":{},"key":["profileDetails","address","addressDetails","","addressType"],"type":"select","titleMap":[{"name":"test","value":"test"},{"name":"test1","value":"test1"}]}]}]}]}]}}],[{"msg":"schemaForm.form[0]","newVal":{"title":"profileDetails","schema":"<>","ngModelOptions":{},"type":"fieldset","items":[{"title":"address","schema":"<>","ngModelOptions":{},"type":"fieldset","items":[{"title":"Contact Person","schema":"<>","ngModelOptions":{},"type":"array","key":["profileDetails","address","addressDetails"],"items":[{"title":"addressDetails","schema":"<>","ngModelOptions":{},"type":"fieldset","items":[{"title":"Contact Type","description":"Select","schema":"<>","ngModelOptions":{},"key":["profileDetails","address","addressDetails","","addressType"],"type":"select","titleMap":[{"name":"test","value":"test"},{"name":"test1","value":"test1"}]}]}]}]}]}}],[{"msg":"schemaForm.form[0]","newVal":{"title":"profileDetails","schema":"<>","ngModelOptions":{},"type":"fieldset","items":[{"title":"address","schema":"<>","ngModelOptions":{},"type":"fieldset","items":[{"title":"Contact Person","schema":"<>","ngModelOptions":{},"type":"array","key":["profileDetails","address","addressDetails"],"items":[{"title":"addressDetails","schema":"<>","ngModelOptions":{},"type":"fieldset","items":[{"title":"Contact Type","description":"Select","schema":"<>","ngModelOptions":{},"key":["profileDetails","address","addressDetails","","addressType"],"type":"select","titleMap":

@shikshik
Copy link

shikshik commented Nov 8, 2015

@senthilsendhil There is typo
"$scop.form" should be "$scope.form" (might be the issue for your case)
Cheers.

@Anthropic
Copy link
Member

Please re-open if you do not feel the question has been answered sufficiently.

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

4 participants