Unable to access g_form in widget code

Dave Clemmer
Mega Guru

I am working my way through a method for one service portal page to call another and pass arguments.  At least, that's the idea.

As a waypoint along that path, I am trying to write a widget version of onChange().  Yes, $rootScope.$on('field.change', function(e,a) {...}) is the overall mechanism.  Anyway, for various reasons, within that method, I want to access all the fields for this form (the widget in question is a copy of the OOTB form widget.  So far, the only change is this onChange() handler, which is in the client controller).  So, ideally, I would access the g_form object (which, thanks to code created for the old UI, but which did only most of what I wanted, I know exists).  I've read, in several places, that $scope.page.g_form should provide that.

It doesn't.  The $scope.page object does exist, but it has no g_form property (nor anything close, come to that.  All of its properties, so far as I can tell, are strings).

Any thoughts on what stupid mistake I undoubtedly made here?

Thanks,

Dave

1 ACCEPTED SOLUTION

 

Dave, 

Get the reference at initialization, then use it on field change:

            var g_form;
            $scope.$on('spModel.gForm.initialized', function(e, gFormInstance) {
                g_form = gFormInstance;
            });

View solution in original post

10 REPLIES 10

@Dave Clemmer HMM I see if i understood it correctly in the info message you are getting undefined when using$scope.page.g_form?

can you try this once?

$rootScope.$on('field.change', function(evt,parms) {

   var g_form = $scope.page.g_form;

   spUtil.addInfoMessage("Form obj: " + JSON.stringify(g_form));

 });

Coz it just worked for me in my instance 

I have already tried it, using both that 'frm' variable, and by directly trying 

spUtil.addInfoMessage("Form obj: " + JSON.stringify($scope.page.g_form));

I get the same result with every variation I've tried.

Thanks again,

Dave

@Dave Clemmer ,

where are you using this widget ?

is it in catalog item?

No, it's a custom page that has only the (slightly) modified form widget and a slightly modified Icon Link widget (if I can figure this part out, the Icon Link will become important.  So far, it isn't).

-Dave

okay so @Dave Clemmer you are using form widget right ?

what was the modification done ?