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

The expression-related settings (defaultValueExpression, resetValueExpression, setValueExpression) are preserved when an Expression field is converted from another question #6641

Open
JaneSjs opened this issue Feb 24, 2025 · 0 comments
Labels
bug user issue An issue or bug reported by users.

Comments

@JaneSjs
Copy link
Contributor

JaneSjs commented Feb 24, 2025

T22023 - Possible bug in survey creator
https://surveyjs.answerdesk.io/internal/ticket/details/T22023


Consider the following survey JSON:

{
  "pages": [
    {
      "name": "page1",
      "title": "Page 1",
      "elements": [
        {
          "type": "boolean",
          "name": "copyValue",
          "title": "Copy value"
        },
        {
          "type": "text",
          "name": "sourceQuestion",
          "title": "Source Question",
          "defaultValue": "Source Value"
        },
        {
          "type": "text",
          "name": "targetQuestion",
          "title": "Target Question",
          "resetValueIf": "{copyValue} = false",
          "setValueIf": "{copyValue} = true",
          "setValueExpression": "{sourceQuestion}",
          "defaultValueExpression": "today()"
        }
      ]
    }
  ]
}

The targetQuestion contains various expression-related settings. If you convert this question to Expression, these settings are preserved:

{
          "type": "expression",
          "name": "targetQuestion",
          "title": "Target Question",
          "resetValueIf": "{copyValue} = false",
          "setValueIf": "{copyValue} = true",
          "setValueExpression": "{sourceQuestion}",
          "defaultValueExpression": "today()"
}

The full survey JSON:

{
  "pages": [
    {
      "name": "page1",
      "title": "Page 1",
      "elements": [
        {
          "type": "boolean",
          "name": "copyValue",
          "title": "Copy value"
        },
        {
          "type": "text",
          "name": "sourceQuestion",
          "title": "Source Question",
          "defaultValue": "Source Value"
        },
        {
          "type": "expression",
          "name": "targetQuestion",
          "title": "Target Question",
          "resetValueIf": "{copyValue} = false",
          "setValueIf": "{copyValue} = true",
          "setValueExpression": "{sourceQuestion}",
          "defaultValueExpression": "today()"
        }
      ]
    }
  ]
}

However, the Expression field expects that it's expression is defined rather than those expression settings. If you define the expression property value, those expression-related settings have no effect.

{
          "type": "expression",
          "name": "targetQuestion",
          "title": "Target Question",
          "resetValueIf": "{copyValue} = false",
          "setValueIf": "{copyValue} = true",
          "setValueExpression": "{sourceQuestion}",
          "defaultValueExpression": "today()",
          "expression": "{sourceQuestion}"
}

A full JSON:

{
  "pages": [
    {
      "name": "page1",
      "title": "Page 1",
      "elements": [
        {
          "type": "boolean",
          "name": "copyValue",
          "title": "Copy value"
        },
        {
          "type": "text",
          "name": "sourceQuestion",
          "title": "Source Question",
          "defaultValue": "Source Value"
        },
        {
          "type": "expression",
          "name": "targetQuestion",
          "title": "Target Question",
          "resetValueIf": "{copyValue} = false",
          "setValueIf": "{copyValue} = true",
          "setValueExpression": "{sourceQuestion}",
          "defaultValueExpression": "today()",
          "expression": "{sourceQuestion}"
        }
      ]
    }
  ]
}

In the original ticket, a user expects that defaultValueExpression is reset when an Expression field is being converted from another question type.

@JaneSjs JaneSjs added bug user issue An issue or bug reported by users. labels Feb 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug user issue An issue or bug reported by users.
Projects
None yet
Development

No branches or pull requests

1 participant