formio / formio.js

JavaScript powered Forms with JSON Form Builder
https://formio.github.io/formio.js
MIT License
1.9k stars 1.07k forks source link

[BUG] Select component's dynamic data inaccessible if default value is set in conjunction with valueProperty #5059

Closed domichal closed 4 months ago

domichal commented 1 year ago

Environment

Steps to Reproduce

  1. open jsfiddle attached below
  2. select value from the dropdown while ignoring incorrect default
  3. observe fields below being populated
  4. uncomment valueProperty line (:35)
  5. notice default value being correct now
  6. select value from the dropdown
  7. observe fields not being populated

Expected behavior

Fields being populated AND default value is set correctly

Observed behavior

With valueProperty set I have no access to the component data so related fields can't be populated

Example

https://jsfiddle.net/domichal/snm1g2hd/

For code or form JSON, please enclose in a code block:

const form = {
    "display": "form",
    "components": [
      {
        "label": "Pick something",
        "widget": "choicesjs",
        "tableView": true,        
        "dataSrc": "url",
        "data": {
          "url": "https://examples.form.io/customer/submission"          
        },
        "template": "<span>{{item.data.firstName}}, {{item.data.lastName}}</span>",
        "validate": {
          "select": false
        },
        "key": "selector",
        "logic": [
          {
            "name": "updateFields",
            "trigger": {
              "type": "event",
              "event": "change"
            },
            "actions": [
              {
                "name": "updateFieldsAction",
                "type": "customAction",
                "customAction": "submission.data.firstname=value.data.firstName;submission.data.lastname=value.data.lastName;submission.data.email=value.data.email"
              }
            ]
          }
        ],
        "type": "select",
        "searchField": "",
        /* "valueProperty": "data.email", */
        "limit": 20,
        "input": true,
        "lazyLoad": true,
        "selectValues": "",
        "disableLimit": false
      },
      {
        "label": "name",
        "tableView": false,
        "redrawOn": "selector",
        "allowCalculateOverride": true,
        "key": "firstname",
        "type": "textfield",
        "input": true
      },
      {
        "label": "last name",
        "tableView": false,
        "redrawOn": "selector",
        "allowCalculateOverride": true,
        "key": "lastname",
        "type": "textfield",
        "input": true        
      },
      {
        "label": "email",
        "tableView": false,
        "redrawOn": "selector",
        "allowCalculateOverride": true,
        "key": "email",
        "type": "textarea",
        "input": true        
      }
    ]
  }

Formio.createForm(document.getElementById('formio'), form).then(function(form) {
  // Defaults are provided as follows.
  form.submission = {
    data: {
      selector: 'joe@example.com'
    }
  };
});
ryanformio commented 4 months ago

Here's a new JsFiddle that I believe should resolve the issue you're dealing with. https://jsfiddle.net/cs197pqt/

image