2

Currently, I'm using ng-jsoneditor.

I'm trying to toggle the state from editable to read-only.

To set the readonly property I have to specify the onEditable property of the options property. For instance:

 $scope.obj = {
            data: json, 
            options: {
                mode: 'tree',
                onEditable: function(){return false;}
            }
  };

I am able to get the changeOptions property to toggle the mode property, however I cannot get the onEditable property to toggle. I want the user to have the capability to edit the json while in the 'code' mode. This is what I tried:

    $scope.changeOptions = function () {
        $scope.obj.options.mode = $scope.obj.options.mode == 'tree' ? 'code' : 'tree';
        $scope.obj.options.onEditable = $scope.obj.options.onEditable == function(){return false;} ?  function(){return true;} :  function(){return false;};
    };

JsFiddle Example

1 Answer 1

1

Edit:

Didn't quite get your question at first, my bad.

In your example what you were doing wrong was checking a variable for a function definition which is onEditable(), which quite does not work.

So what I did was check if mode is tree or code then assign a function to onEditable option of ng-jsoneditor.

Here is the updated fiddle.

PS: I did clean some code as well.

Sign up to request clarification or add additional context in comments.

2 Comments

Oh yea? Did you test the demo? Did you notice the demo allows you to edit both in tree mode and code mode? I want to disable the capabilities of editing while in tree mode. The use case is basically, while in tree mode make the editor read only and while in code mode allow the user to modify the json.
@PhiL please check now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.