How to delete jcr value of cq:dialog granite field, when it's hidden ? | Community
Skip to main content
KotiSyamala
Level 5
February 3, 2020
Solved

How to delete jcr value of cq:dialog granite field, when it's hidden ?

  • February 3, 2020
  • 3 replies
  • 3168 views

Dear Community

I've a requirement to hide and show two input fields based on selection dropdown, if the input1 is hidden input2 is shown. But the input is already authored the value is shown when the selection changes.

 

Please help me to remove the jcr value of input1 when it's hidden?

 

Thanks,

Koti Syamala

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by ashish_mishra1

You can use this dialog validation code to achieve this. Here, we will be setting either of the input value is null. if another field is selected using the dropdown.

 

(function(document, $, ns) { "use strict"; $(document).on("click", ".cq-dialog-submit", function(e) { e.stopPropagation(); e.preventDefault(); var $form = $(this).closest("form.foundation-form"), selectionDropDown = $form.find("[name='./selectionDropDown']").val(), message, clazz = "coral-Button "; if (selectionDropDown == 'selected-input2') { $('[name="./input1"]').val(''); } if (selectionDropDown == 'selected-input1') { $('[name="./input2"]').val(''); } $form.submit(); }); })(document, Granite.$, Granite.author);

 

3 replies

Adobe Employee
February 3, 2020

You can user "granite:hide" property. Check [1] for more details.

 

[1] https://docs.adobe.com/content/help/en/experience-manager-65/developing/components/hide-conditions.html

ashish_mishra1Accepted solution
Level 3
February 5, 2020

You can use this dialog validation code to achieve this. Here, we will be setting either of the input value is null. if another field is selected using the dropdown.

 

(function(document, $, ns) { "use strict"; $(document).on("click", ".cq-dialog-submit", function(e) { e.stopPropagation(); e.preventDefault(); var $form = $(this).closest("form.foundation-form"), selectionDropDown = $form.find("[name='./selectionDropDown']").val(), message, clazz = "coral-Button "; if (selectionDropDown == 'selected-input2') { $('[name="./input1"]').val(''); } if (selectionDropDown == 'selected-input1') { $('[name="./input2"]').val(''); } $form.submit(); }); })(document, Granite.$, Granite.author);

 

KotiSyamala
Level 5
February 17, 2020

Thanks for the clientLibs solution.

 

Hi Adobe Team, @kautuk_sahni @user05162 @ashish_mishra1 @joerghoh @smacdonald2008 

 

This is a common use case can we add this as a flag to not to submit if it's hidden in granite type?

Thanks,
Koti.