close uibModal after submitting embedded widget-form

davilu
Mega Sage

Hi Everyone, our team is developing a widget with widget-form embedded in a modal.  Our code for it so far looks like this:

<div ng-if="!c.list[0]"> 
  <p class="h3">Fill out this questionnaire</p>
    <button class="btn" ng-click="c.newEntry()">
      <i class="far fa-clipboard fa-7x"></i>
    </button>
  <p class="h4">Let's Get Started</p> 
</div>

<script>
  <div>
     <sp-widget widget="c.newQuestionnaire"></sp-widget>
  </div>
</script>
		c.newEntry = function() {
			c.modalInstance = $uibModal.open({
				templateUrl: 'newQuestionnaire',
				scope: $scope,
				size: 'lg'
			});
			spUtil.get("widget-form-scoped", {
				sys_id: -1,
				table: 'x_dnf_gw_obf_questionnaire'
			}).then(function(response) {
				c.newQuestionnaire = response;
			});
		}
		

		c.closeModal = function() {
			c.modalInstance.close();
		}

 

Currently, when a user submits the embedded form, the modal remains open.  Is there a way to close the modal once the form has been submitted?  I'm guessing I will have to add something to widget-form-scoped, but not sure how to go about this in the cleanest way.  Any suggestions?

 

EDIT:

I managed to figure out how to close the modal when the form is submitted as a new record by using a recordWatch:

	spUtil.recordWatch($scope, 'x_dnf_gw_obf_questionnaire', "",function(event,data){
		spUtil.update($scope);	
		c.runServer();	
		c.closeModal();
	});	

However, this doesn't work when a user opens an existing records and Updates.  Any suggestions on how I can have the modal close on both Record Added and Updated?

Thanks!

5 REPLIES 5

Mike Patel
Tera Sage
Just add c.modalInstance.close(); after question response

davilu
Mega Sage

Hey Mike, thanks for the response, but where would I put that line of code?  I tried putting it in after c.newQuestionnaire = response; but it doesn't work.

After c.newQuestionnaire = response; });

that doesn't work unfortunately.  thanks.