To access widgets inside the event listeners of any widget, follow the below step.
- Get the "dialog" object first.
- var dailogObject = this.findParentByType('dialog');
- This will return the dialog object associated with your compoent dialog. Then look for the corresponding widget by invoking
- var titleField = dailogObject .getField('./jcr:title');
- The above function looks for a widget by name './jcr:title' and returns the widget object associated.
Use case scenario.
Let's create a component dialog with 2 widgets (Pathfield, TextField).
use case 1: if author selects any link URL then the corresponding title of the page should be set into the TextField widget.
Below steps can be followed to achieve this.
- create a component dialog with two widgets.
- One path field with name "./path" and xtype is "pathfield"
- Text field with name "./title" and xtype is "textfield"
- Attach a listener to the path field. And add "dialogclose" event to the listener.
- The javascript function for the above event can be written as below.
- This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
function(){ var componentDialog = this.findParentByType('dialog'); // returns the dialog object var titleWidget = componentDialog.getField("./title"); var selectedPath = this.value;// returns the selected path from the path field //Can write a remote service which returns the title of any path selected $.get("/someRemoteService",{'path':selectedPath}).done(function(data){ titleWidget.setValue( data ); }); } - Sample screen shot
Nice Abani I'm simply trying to create an input field from a dropdown menu can you help me out with that...Thanks
ReplyDeleteI wanted to add a listener to my dialog, came across your blog while surfing net. Good Job Sir!!!
ReplyDeleteHi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Java developer learn from Java Training in Chennai. or learn thru Java EE Online Training from India . Nowadays Java has tons of job opportunities on various vertical industry.
ReplyDelete