How to access widgetInput data

dgarnica
Tera Contributor

Hi experts,

 

I'm starting with Widgets and I'm need to pass a value from the spModal to the widget, I'm trying the "widgetInput" parameter, for example:

 

spModal.open({
            title: 'My First Widget,
            widget: "my_first_widget",
            widgetInput: {
                test: '111233555'
            },
            size:"md"
        }).then(function(){
           
        }) ;  
 
Is there an option to read a value passed from the spModal?, I tried with data or input, for example: input.test or data.test but it doesn't get the value in the Widget.
1 ACCEPTED SOLUTION

ChrisBurks
Mega Sage

Hi @dgarnica ,

 

One possible solution is to use the $scope property named "widget_parameters". If you add a property called "shared" to the object passed to the spModal.open() method, it will be added to the widget_parameters property on the current widget $scope and it will be accessible in both the modal and the calling widget.

Here is a basic example:

Widget that opens the spModal

HTML:

<div>
  <h3>
    Hello 
    <span ng-hide="c.MySharedVar.person">_______</span>
    <span ng-show="c.MySharedVar.person" class="text-success">{{c.MySharedVar.person}}</span>
   !
  </h3>
  
  <button class="btn btn-default" ng-click="c.openModal()">
    Get Person
  </button>

</div>

Client Controller:

api.controller=function($scope, spModal) {

	var c = this;

	c.MySharedVar = {
		"person":"",
	};

	c.openModal = function() {
		spModal.open({
			"title":"My First Widget",
			"shared": c.MySharedVar,
			"widget": "my-first-widget",
			"size":"md",
			buttons:[
				{"label":"Cancel", "cancel":true},
				{"label": "Ok", "primary":true}
			],
			
		});
	}
};

 

Widget appearing in the modal (my-first-widget)

HTML

<div>
 <form>
   <div class="form-group">
     <label for="FirstInputPerson">Who Am I</label>
     <input id="FirstInputPerson" class="form-control" ng-model="c.MySharedVar.person">
   </div>
  </form>
</div>

Client Controller

api.controller=function($scope) {
  var c = this;
	
	c.MySharedVar = $scope.widget_parameters.shared;

};

 

Rendered Demo:

Pass object from Modal back to WidgetPass object from Modal back to Widget

 

View solution in original post

5 REPLIES 5

Hi @ChrisBurks 

 

I achieved the decision based with a ternary condition in the "ng-click" attribute of the button, getting the result from the function called at the first time and setting a close action in case of a specific result.

 

I'll try other use case with the $scope function that you're sharing as example.

 

Thanks a lot for the help.