I have a component that has its cq:dialog file, something I need to do is to perform some validations based on the selected dropdown value.
I already have the logic but what I can't get is to obtain the selected value of the dropdown of the cq:dialog
I already tried using:
-- let dropdownValue = $('#sliderTypeValue');
But none of them brings me the value of the the dropdown field on cq:dialog authoring.
What can I do in this case?
This is the cq:dialog dropdown I create:
Solved! Go to Solution.
Views
Replies
Total Likes
There are several approaches to retrieve the dropdown selection. Here are a few examples:
// by name
let dropdownValue = $("[name='./slideType']").val()
// by granite:class
let dropdownValue = $(".cq-dialog-dropdown-showhide").val()
You can check the Inspect Element for better understanding
@Aaron_Dempwolff Please give this a shot and see if it works and modify the selector accordingly
(function($, $document) {
$('#ContentFrame').on('load', function() {
var iframe = $(this)[0],
iframeDocument = iframe.contentDocument ? iframe.contentDocument : iframe.contentWindow.document;
var dd = $(iframeDocument).find('.sliderTypeValue')
console.log($(dd).val());
}
})($, $(document));
There are several approaches to retrieve the dropdown selection. Here are a few examples:
// by name
let dropdownValue = $("[name='./slideType']").val()
// by granite:class
let dropdownValue = $(".cq-dialog-dropdown-showhide").val()
You can check the Inspect Element for better understanding
Can you try var varSel = $('input[name="./sampleName"]');
Write an event trigger on change of dropdown value and add the above piece of code. You can change the selector to class or id as per your need. This should work.
If it does not try adding debug breakpoints in Chrome Developer tools and see what element is getting captured.
Thanks,
Authoring dialog values are only available at the authoring clientlibs. Based on the information provided in your question, it's not clear in which JS you are trying to access the value of the authoring dialog dropdown of interest.
I would suggest, within your component folder, create a new clientlib folder called "clientlib-author" with the following properties
allowProxy="{Boolean}true"
categories="[cq.authoring.dialog,granite.ui.foundation.admin]"
Within this clientlib folder, create a js.txt and author clientlib JS "listeners.js" (you may choose any other name as well but remember to define the same file name in js.txt).
Within the "listeners.js",
(function($, $document) {
"use strict";
$('#ContentFrame').on('load', function() {
var iframe = $(this)[0],
iframeDocument = iframe.contentDocument ? iframe.contentDocument : iframe.contentWindow.document;
var dd = $(iframeDocument).find('.sliderTypeValue')
console.log($(dd).val());
//Do your stuff here
}
})($, $(document));
Hope this helps!