- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-13-2017 06:07 AM
I have a widget that has an option, called "message". In one place, I have embedded this widget in another widget. I have created an option called "message" on the parent widget.
How do i link the parent widget's option to the embedded widget?
The solution is this:
function(spUtil) { /* widget controller */
var c = this;
spUtil.get("custom-search-page", {message: c.options.message}).then(function(response) {
c.data.parentMessage = response.options.incident_message;
c.data.parentMessageFlag = 'true';
});
}
I'm not positive i understand exactly what is happening, but it's behaving the way i want it to.
The widget im using is embedded sometimes, and not at other times. The widget is a button with a string of text above it. I set the value of that string with instance options. I wanted to be able to set that text even when it's embedded in this widget.
from what i understand, the SPutil gets the message i ask for from the widget i specify, and returns a promise. When the promise comes back, i set a data paramenter to equal the response field, and set a flag to true.
in my server script i check to see if the flag is true. if it is, I display the parent message. otherwise i use the one local to the widget.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-13-2017 06:12 PM
You can use the following in your server script:
data.widget = $sp.getWidget("widget-id", options);
The second parameter is the object being passed in to the widget, so this should pass all available "options" on the first widget in to the embedded widget. I haven't tested this, but 99% certain it'll work.
And then all you have to do is display the widget in your HTML:
<sp-widget widget="data.widget"></sp-widget>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-13-2017 06:12 PM
You can use the following in your server script:
data.widget = $sp.getWidget("widget-id", options);
The second parameter is the object being passed in to the widget, so this should pass all available "options" on the first widget in to the embedded widget. I haven't tested this, but 99% certain it'll work.
And then all you have to do is display the widget in your HTML:
<sp-widget widget="data.widget"></sp-widget>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-14-2017 08:11 AM
I ended up doing this in the controller:
function(spUtil) { /* widget controller */
var c = this;
spUtil.get("custom-search-page", {message: c.options.message}).then(function(response) {
c.data.parentMessage = response.options.incident_message;
c.data.parentMessageFlag = 'true';
});
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-14-2017 08:43 AM
just to be clear, This goes in the server script of the embedded widget, and the widget id is the name of the parent widget, correct?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-14-2017 08:59 AM
Andrew,
The script I showed goes in the parent server script, it passes the options in to the embedded widget. The disadvantage of doing it in the controller is that it requires an AJAX call to the server as opposed to handling everything on the server.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-14-2017 09:04 AM
OK, thanks for clarifying that. Just so im clear, in your example, this creates the "widget" object on the embedded widget? or do i have to create it in the embedded widget as well?
