Question T5873
Visible to All Users

Element type imagepicker

created 5 years ago

Hello.
I am trying to populate a 'choices' property (array) of a imagepicker element. Other elements that accept 'choices' use the Survey.ItemValue() to create elements but imagepicker extends the ItemValue() method as ImageItemValue().

Tracing (in question_imagepicker.ts) the population of a 'choices' array I see that an object of class ImageItemValue is instantiated from a call from Serialize.addclass() but there my understanding stops.

How do / can I instantiate an ImageItemValue object without invoking the code in jsonobjects.ts ?

Met vriendelijk groeten,
Max

Answers approved by surveyjs Support

created 5 years ago

Hello,

You can simply assign choices from a JSON array:

JavaScript
survey.getAllQuestions()[0].choices = [ { "value": "lion", "imageLink": "https://surveyjs.io/Content/Images/examples/image-picker/lion.jpg" }, { "value": "giraffe", "imageLink": "https://surveyjs.io/Content/Images/examples/image-picker/giraffe.jpg" }, { "value": "panda", "imageLink": "https://surveyjs.io/Content/Images/examples/image-picker/panda.jpg" }, { "value": "camel", "imageLink": "https://surveyjs.io/Content/Images/examples/image-picker/camel.jpg" } ];

Here is the working sample - https://plnkr.co/edit/xsJyEMr4Ny1tXHDk

Thanks, Serge
SurveyJS Team

    Show previous comments (2)

      Hello,

      Yes, you need to set the

      JSON
      "showLabel": true,

      property.

      Here is the working sample - https://plnkr.co/edit/vmx8fpbExtHFGgot

      Thanks, Serge
      SurveyJS Team

        … but the element has no 'label' property (not intuitive ;)
        Spaciba!

        From: Serge T [surveyjs Support]
        Sent: Wednesday, December 09, 2020 8:12 PM
        To: d04105641@inbox.lv
        Subject: RE: Element type imagepicker [T5873]

          Hello,

          Thank you for the feedback! We'll keep it in mind.

          Thanks, Serge
          SurveyJS Team