Fill drop down list with a calculated total

Avatar

Avatar
Ignite 1
Level 1
wilsonl28824783
Level 1

Likes

0 likes

Total Posts

4 posts

Correct reply

0 solutions
Top badges earned
Ignite 1
View profile

Avatar
Ignite 1
Level 1
wilsonl28824783
Level 1

Likes

0 likes

Total Posts

4 posts

Correct reply

0 solutions
Top badges earned
Ignite 1
View profile
wilsonl28824783
Level 1

23-06-2020

I have a calculated field that totals the difference between two numbers; is there a way to use that generated total and populate a drop down?

 

example: the calculation is 5; is there a way to populate a drop down list that would show 0,1,2,3,4,5?

I think some combination of a For loop and an array might do it, however, I am no good at script writing and I would really appreciate an example 😌

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Springboard
Level 10
Mayank_Gandhi
Level 10

Likes

327 likes

Total Posts

1,150 posts

Correct reply

185 solutions
Top badges earned
Springboard
Establish
Validate 1
Contributor 2
Ignite 5
View profile

Avatar
Springboard
Level 10
Mayank_Gandhi
Level 10

Likes

327 likes

Total Posts

1,150 posts

Correct reply

185 solutions
Top badges earned
Springboard
Establish
Validate 1
Contributor 2
Ignite 5
View profile
Mayank_Gandhi
Level 10

01-07-2020

@wilsonl28824783 

Try adding the calculated element using JS i.e  DropDown.addItem("Last Item," Calculated Value");

Answers (2)

Answers (2)

Avatar

Avatar
Establish
MVP
Nupur_Jain
MVP

Likes

165 likes

Total Posts

186 posts

Correct reply

76 solutions
Top badges earned
Establish
Ignite 1
Give Back 5
Give Back 3
Give Back 25
View profile

Avatar
Establish
MVP
Nupur_Jain
MVP

Likes

165 likes

Total Posts

186 posts

Correct reply

76 solutions
Top badges earned
Establish
Ignite 1
Give Back 5
Give Back 3
Give Back 25
View profile
Nupur_Jain
MVP

02-07-2020

Hi @wilsonl28824783 

 

You can achieve your requirment using Jquery. Find the code snippet to dynamically add values to dropdown.

 

(function ($, $document) {
	"use strict";
	// Add granite:class='custom-dynamic-selection' on selection node on cq:dialog
	const SELECTION_SELECTOR = ".custom-dynamic-selection";

	$document.on("dialog-ready", function () {
		// Change this value after calculating it
		var dynamicLength = 5;
		populateDropdown(dynamicLength);
	});

	function populateDropdown(length) {
		var dynamicSelection = $(SELECTION_SELECTOR);
		if (dynamicSelection.length) {
			dynamicSelection[0].items.clear();
			for (var number = 1; number <= length; number++) {
				var selectItem = {};
				selectItem.content = {};
				selectItem.content.textContent = number;
				selectItem.value = number;
				dynamicSelection[0].items.add(selectItem);
			}
		}
	}

}(jQuery, jQuery(document)));

 

Add this js in "cq.authoring.dialog" clientlibs and add property granite:class on selection like this

Screenshot from 2020-07-02 12-56-12.png

 

Hope it helps!

Thanks,

Nupur

Avatar

Avatar
Ignite 1
Level 7
GirishBedekar
Level 7

Likes

167 likes

Total Posts

241 posts

Correct reply

37 solutions
Top badges earned
Ignite 1
Give Back 5
Give Back 3
Give Back 10
Give Back
View profile

Avatar
Ignite 1
Level 7
GirishBedekar
Level 7

Likes

167 likes

Total Posts

241 posts

Correct reply

37 solutions
Top badges earned
Ignite 1
Give Back 5
Give Back 3
Give Back 10
Give Back
View profile
GirishBedekar
Level 7

23-06-2020

Is this adaptive form?