survey-creator icon indicating copy to clipboard operation
survey-creator copied to clipboard

is there any way we can get currently focused ItemValue in choices question like QuestionDropdownModel , QuestionCheckboxModel

Open kundaria opened this issue 1 year ago • 1 comments

surveyjs creator event to add extra data to currently focused choice itemValue of choice questions and save that surveyjs questions with extra data added to currently focused choice itemValue

i have used code : this.currentSelectedQuestion.onItemValuePropertyChanged() this event but its not working. i want to get currently focused itemvalue so i can update its custom property like selected_products

creator.onSelectedElementChanged.add((sender, options) => {

        if (options.newSelectedElement.getType() === 'radiogroup' || options.newSelectedElement.getType() === 'checkbox' || options.newSelectedElement.getType() === 'dropdown' || options.newSelectedElement.getType() === 'boolean' || options.newSelectedElement.getType() === 'text') {
         
          this.currentSelectedQuestion = options.newSelectedElement;

          // Add event listener for item value property changed
          this.currentSelectedQuestion.onItemValuePropertyChanged.add((sender11, options11) => {
            console.log('onItemValuePropertyChanged',options11);
            if (options11.propertyName === 'choices') {
              var choices = options11.obj.choices;
              choices.forEach(function (choice, index) {
                choice.onItemValuePropertyChanged.add((sender1, options1) => {
                  if (options1.propertyName === 'isFocused') {
                    // Custom HTML can be added here based on the clicked choice
                    alert("Custom HTML for Option " + (index + 1));
                  }
                });
              });
            }
          });
        
        } else {
        
          this.productsTree = [];
        }
      
      });

kundaria avatar Mar 25 '24 07:03 kundaria

Hello @kundaria, If you wish to add an extra data to a choice object, you can follow these steps:

  • Use a Serializer API and register a custom property for the itemvalue object. You can specify the default value for the custom property.
  • Handle the creator.onItemValueAdded event and specify a new value for a custom property when a new item value is added. Let me know if this works for you. Otherwise, I'll assist you further.

P.S. Let me note that SurveyJS Creator is available under a commercial developer license. Commercial users can receive technical support from Help Desk.

JaneSjs avatar May 29 '24 12:05 JaneSjs