Hello, I observed a lot of people asking the same question or similar kind of, How to Hide/Show field based on selection.
Just not to over load this post, here we will see how to Show/Hide fields based on checkbox selection in this post and in next post we will see how to achieve the same thing on radio button selection.
See how to AEM: Hide/Show Touch UI dialog fields based on radio selection
Let's get started
See how to Create custom Touch Dialog UI edit client libraries
Now we know how to create the custom client library and we created and configured in our dialog.
Here I have a Demo Component and in the dialog I have 3 fields as show in below image.
Here we have 2 text fields and a checkbox. Let us see to to show/hide the Sub Title field based on checkbox(Hide Sub Title) selection.
Below is the node and properties for checkbox.
Note: It is recommended to set value, uncheckedValue properties. Check below documentation for checkbox.
We have listener.js file in our custom client library that we created, let us open that.
listener.js
Let's add a self executable function, inside that add dialog ready event.
(function ($, document, ns) {
$(document).on("dialog-ready", function() {
});
})(Granite.$, document, Granite.author);
The dialog ready event listener(or call back) will be fired once dialog is ready.
Now let's write a change event listener for checkbox in side dialog ready.
Note: The highlighted name should be updated.
Now Save the changes and hard reload the page and open the dialog.
Check and un-check the checkbox and you can see the sub-title field is hiding and showing upon selection.
Hurrah.... We have successfully achieved the hide and show functionality based on checkbox selection.
No comments:
Post a Comment