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

Pre-fill model value - set multiple values #941

Open
bcbirkhauser opened this issue Nov 22, 2017 · 1 comment
Open

Pre-fill model value - set multiple values #941

bcbirkhauser opened this issue Nov 22, 2017 · 1 comment

Comments

@bcbirkhauser
Copy link

Question

I have multiple yes/no radio buttons and I have one that I want to use to set the values for all the others, a "All Yes/All No" radio button. I have a callback on the change to set the model values, but it doesn't actually update the ui.
I also have a need to be able to pre-populate the form with saved answers if a user comes back to the form, which I assume will be a similar function.

How do I set the model value and get the ui to update with the correct values?

Here is what I'm doing when the user toggles the all yes/no radio.

//key = ['section', 'field']
toggleAll(key, value) {
    const section = key[0];
    _.each(this.$scope.schema.properties, (obj, k) => {
      if(k !== section + '.all') {
        this.$scope.model[section][k.replace(section + '.', '')] = value;
      }
    });
  }

Here is my form schema for that particular all yes/no field

{
          "key": "groupOne.all",
          "type": "radios",
          "onChange": "toggleAll(form.key, modelValue)",
          "titleMap": [
            {
              "value": "yes",
              "name": "All Yes"
            },
            {
              "value": "no",
              "name": "All No"
            }
          ]
        },
    {
          "key": "groupOne.questionOne",
          "title": "This is a placeholder question?",
          "type": "radios",
          "titleMap": [
            {
              "value": "Yes",
              "name": "Yes"
            },
            {
              "value": "No",
              "name": "No"
            }
          ]
        },
@scottux
Copy link
Contributor

scottux commented Aug 12, 2018

https://github.com/json-schema-form/json-schema-form/wiki/Documentation#copyvalueto

This might help. Other than possibly needing a $scope.$apply() though, I don't see anything wrong with your code or why it wouldn't work like you are expecting.

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