Survey-library: question.value is undefined in custom widgets if set to []

Created on 15 Nov 2017  路  4Comments  路  Source: surveyjs/survey-library

Are you requesting a feature, reporting a bug or ask a question?

Bug

What is the current behavior?

question.value is undefined in afterRender if set to an empty array

What is the expected behavior?

That I can assign question.value in afterRender to be equal to an empty array

let getOpCodesWidget = () => {
    var widget = {
        name: "myWidget",
        isFit: function (question) { return question["renderAs"] === 'myWidget'; },
        htmlTemplate: myWidgetTemplate,
        afterRender: function (question, el) {
              question.value = [];
              question.value.push('item'); // this fails because the value is undefined
        }
    }
    return widget;
}

Specify your

  • browser: any
  • browser version: any
  • surveyjs platform (angular or react or jquery or knockout or vue): jquery
  • surveyjs version: latest

All 4 comments

@faso Could you try:

let newValue = [];
newValue.push('item');
question.value = newValue;

Thank you,
Andrew

But if I do

let newValue = [];
question.value = newValue;

It's still undefined. Why so?

@faso Because the library change the empty array into undefined value, if the array is empty. Empty array should not be in the survey result and required value check should produce the error.

Thank you,
Andrew

Alright, thank you for quick answers. Always a joy to get help from you guys!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

spertusatti picture spertusatti  路  3Comments

GuiAfonso picture GuiAfonso  路  4Comments

misamura picture misamura  路  4Comments

aslanbeily picture aslanbeily  路  4Comments

nadialo picture nadialo  路  4Comments