Service Portal widget event handler

Tommy Jensen
Giga Guru

I want to add an event handler for when the form has been loaded so I added following in the Client script in a new widget. 

$rootScope.$on('spModel.gForm.initialized', function (e, gFormInstance) {
		console.log('In spModel.gForm.initialized');   
    });

I have also tried

$scope.$on('spModel.gForm.initialized', function (e, gFormInstance) {
		console.log('In spModel.gForm.initialized');   
    });

But nothing happens what the pages is loaded.

The weird thing is that I have another widget (more complex one with both client and server scripts) where I use the exact same code and in that widget it works fine.

Of course both $scope and $rootScope is injected with

function($scope, $rootScope)

 

6 REPLIES 6

SatheeshKumar
Kilo Sage

Hi,

i am not familiar with this but adding my points below

 

$rootScope.$emit('spModel.gForm.initialized', id);
	

 

I believe we need to send an event from another widget like the above to make your widget to listen that event.

 

or

 

if (spModel.gForm.initialized) is  a OOB event  that is triggered during  form initialization, then ignore the above !!

 

Thanks,

satheesh

 

 

 

 

The event is an OOB event. 

arthurcheung
Kilo Expert

What about spModel.gForm.env.created?

It appears in the out of the box form widget, as does spModel.gForm.initialized...

$scope.$on('spModel.gForm.env.initialized', function (e, gFormInstance){
  initForm(gFormInstance)
});
$scope.$on('spModel.gForm.env.created', function (e, gFormInstance){
  initForm(gFormInstance)
});

kimkal
Tera Contributor

Did you find a solution for this?

When I reload my page, I don't see the form rendered either.

 

thanks

kalhee