Skip to content
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

Setting a value to an object #533

Closed
nicklasb opened this issue Sep 4, 2015 · 2 comments
Closed

Setting a value to an object #533

nicklasb opened this issue Sep 4, 2015 · 2 comments

Comments

@nicklasb
Copy link
Member

nicklasb commented Sep 4, 2015

Hi!
So I am trying to use a combination of angular-schema-form-ui-ace and $validators, and I am trying my best to not having to create a special plug-in for the job.

There problems:

  1. How do I actually set the model value to the resulting object? The ace-component will set it as a string, so I will have to cut in between or at some stage and set the model. In this example, I desperately tried to set value to the object, however that is not a reference, or at least it doesn't look like that it worked.
  2. Having a function declaration in the json makes it impossible to store it as plain json, I suppose that there is no way of dynamically refer to some function in, for example the controller scope?

This is what I do now. Setting value obviously doesn't work:

        {
            key: "globals",
            type: "ace",
            aceOptions: {
                mode: 'json'
            },
            validationMessage: {
              'noGlobals': 'Globals contains invalid JSON'
            },
            $validators: {
              noGlobals: function(value) {
                  debugger;
                  try {
                      value = JSON.parse(value);
                      return true;
                  }
                  catch (err) {
                      return false;
                  }
              }
            },
            title:"Global variables",
            description: "The global variables that is provided as input to the process"
        }
@davidlgj
Copy link
Contributor

davidlgj commented Sep 5, 2015

Hi @nicklasb!

  1. it might be hard to do without modifying the ace add-on. But you can try to add to the ˋ$parsersˋ and
    ˋ$formattersˋ as well, that could work. Se the ngModel controller docs: https://docs.angularjs.org/api/ng/type/ngModel.NgModelController
  2. Yes that is a problem. Currently you can't do that. What you can do is maybe to add a ˋ"format": "JSON"ˋ to the schema and a custom format validator function to the tv4 validator. That would get rid of the ˋ$validators, but not the ˋ$parsersˋ and
    ˋ$formattersˋ...

@nicklasb
Copy link
Member Author

nicklasb commented Sep 5, 2015

I just realized that I might be going about this the wrong way.
What I was supposed to use this for was actually to edit a dictionary(or object), the only JSON-supported base type that can't be structurally edited by ASF.

The I also thinking about the form builder project, which will have to solve this problem. As it will have to be able to edit JSON objects structurally.
So perhaps what is needed is a "builder" that can edit JSON structures in general either way. If you got that, you could just theoretically plug that in here.

I will look at the $formatters and $parser as well, thanks for you help!

@davidlgj davidlgj closed this as completed Sep 6, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants