i want to 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));
                      }
                    });
                  });
                }
              });
            
            }
          
          });

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));
                      }
                    });
                  });
                }
              });
            
            }
          
          });

i want to get currently focused or selected itemvalue element in choices so i can update custom property value in itemvalue

0

There are 0 best solutions below