How to submit parent window form when child window closes - javascript

I have a gridview displayed in a page which also has a link. When I click on the link, a showModalDialog() will open up where I can edit the value.
After that when pressing Update button the value is getting updated in the database and my child form closes perfectly.
But I need to update my parent page table as well. So that the new value gets reflected in the parent form. I tried the following in the child window.
<body onunload="window.opener.document.forms[0].submit();">
But that is not working. Suggest me a good solution.

You do not have onUnload in a modal dialog
var res = showModalDialog(...); // execution is blocked until modal is closed
if (res) location.reload(1); // res contains what dialog set returnValue to
and in modal dialog you do
window.returnValue=true; // if ok submission
window.close(); // will return control to opening window
Anyway, did you look to the right? there are many duplicate questions about gridviews and modal dialogues

I guess you have a function on Update button click, which updates the database and close the form, can you place that code (the one that you have in unload) in that function before closing the window

Related

How to clear a featherlight modal

I am using feather-light modal in my page. on the modal one form is there with certain input fields. Once I fill in the fields and close the modal and when I open it again , it contains the previously filled data. I want to clear the data once it is closed. I am using angular js in my page.
Can anyone tell me how can I clear the feather-light modal using angular js?
Update-
In my code I have to open another modal after closing the first modal. And once second modal closes, if I am opening my first modal, its showing the previously filled data, I want to reset the modal data of first modal.
in my html I am using below code-
<button type="submit" ng-click="anotherModal(myForm)" ng-class="{ 'featherlight-close' : myForm.$valid}">Submit</button>
and in script I am using below code-
$scope.anotherModal= function (myForm) {
if ($scope.myForm.$valid) {
$scope.myForm.$submitted = true;
$.featherlight("#f12","open");
}
}
Can anyone tell me where should I add to reset the first modal?
Updated Plunker-
Please find my plunker here-
https://plnkr.co/edit/cDP1eqtUsKkeMaUiCIoM?p=preview
I am using persist ='shared' in my code because if I remove this then form validation won't work on first modal.
My issue is that when I open my second modal next time,it contains previously filled values and from there when I click on submit button my second modal doesn't show up.
Can anyone help me in solving my issue?
If you are using the persist option, then yeah, the form is persisted, so you'll have to clear it yourself.
If not, then you'll get a new copied form each time. In that case though, you'll have to be careful about how you bind it and avoid using any IDs, since those are supposed to be unique.
As far as I know featherlight is gallery plugin, used for displaying images in a lightbox. Considering this it is not meant to be used like that (even though you can, but it will not behave as you expect here out of the box), so that's why you'll have to cleanup behind you (or more specific your users), and on popup close action, clear all form fields. There are several ways to do that, eg. form reset button (input type="reset"), js callback on close popup or submit event (or in your case using angular js events), etc..
Since you didn't provide any code that's all I can tell you for now..
Also possible duplicate of Resetting form after submit in Angularjs
UPDATE
Not sure what exactly are you trying to achive here, but if you remove (or move inside showAnotherModal function) $.featherlight.defaults.persist=true; line, it works as you described, first popup is cleared when you open it for second time. Here is your snippet updated:
var app = angular.module('myApp', ['ngMessages']);
app.controller('myCtrl', function($scope) {
// $.featherlight.defaults.persist="shared";
$scope.showAnotherModal = function () {
$.featherlight.defaults.persist="shared";
if ($scope.myForm.$valid) {
$scope.myForm.$submitted = true;
$scope.myForm.dirty = false;
$scope.myForm.$setPristine();
$scope.myForm.$setUntouched();
$.featherlight("#fl3",'open');
}
}
});

How to update the value of a column in my table when the current tab close or navigate to another page?

I have a page and I named it to mypage.php. I have a table MyTable with a column STATUS. I want to update the status to T when the user enters to the page and change to F when the user leaves or close from the page.
I tried with onbeforeunload with JS. Help me any way.
Try
window.onunload=function(){
/......when user closes..../
}
window.onload=function(){
/....when user enters page.../}
I think you should try the "onfocusout" or "blur" event if you want to update it when the user goes on another tab and not only when he close your tab. Put the onfocusout on the body tag and it will fire when the user will exit your tab, by switching to another tab or by closing yours.

PHP Javascript: Closing Popup calling parent window in background

Let's say a parent window is www.mysite.com/index.php has several links. When user clicks on these links, a popup is opened.
The popup has some forms. When the user clicks submit button, another script is called within the popup like this:
if ((isset($_POST['Complete'])) && ($_POST['Complete']=='Complete')) {
unset($_POST['Complete']);
include 'result.php';
return;
}
The result.php enters the data into database and pass the result to parent window with the following
<script language="JavaScript" type="text/javascript">
window.opener.location.href = 'submission.php';
window.close();
</script>
The parent window then show the final result, update the master database and emails the users.
Now here is the problem.
User clicks the link on parents.
Form opens, but user click close (browser cross button).
The user then closes parent window
The user then visit some other page of the site; say other.php
But the master database is getting updated and the user is getting the email (All null values though).
Since the form was never completed, the result.php should never be called. and if result.php is never called, submission.php should never be called.
What is happening here?
Change the type of the close button to button.

CasperJS: How to click a link in a frame that closes the page, without error

I have a form I'm filling and one of the fields requires picking an object from a list in a popup window. The list is inside an iframe on the popup page, and clicking the link in the list closes the popup and places the value in the form on the original page.
My problem is with my setup I'm clicking the link within the iframe kills the popup, and then on exiting the this.withFrame() function I get the error
Error: cannot access member 'switchToParentFrame' of deleted QObject
Here's roughly what my code looks like.
this.withPopup(/popup/, function() {
this.withFrame('listFrame', function() {
// do stuff to get the right link selector
this.click(link);
});
});
If there's a way to click the link from outside the withFrame() function?
A workaround would be to use the PhantomJS functions page.switchToFrame() and page.switchToParentFrame() and explicitly check if the page is still valid. Maybe a check is not even necessary, because the page instance is already destroyed.
this.withPopup(/popup/, function() {
this.page.switchToFrame('listFrame');
this.click(link);
});

Refresh parent window after closing a popup window

I am opening a popup window from X.jsp and the popup is represented by Y.jsp. The second jsp has a button. What I would like to do is to refresh the parent page (the one that launches the popup) once this button is hit. The Save button below will call a method in the backing bean "copyScriptForVersion" and I close the popup on button click. How could I also refresh the parent window after closing the popup?
<h:commandButton type="submit" value="Save" action="#{copyScriptForVersion.SaveAction}" onclick="window.close()"/>
I tried adding window.opener.reload() like this onclick="window.close(); window.opener.reload();", but that didn't work.
I also tried adding the following
body onUnLoad="window.opener.location.reload(1);">
But, I got "window.opener.location is null or not an object" error.
First of all, you should do window.close() as a LAST action in the onClick handler. Otherwise, it's possible it will never get executed.
Second, if reload() doesn't work, try:
window.opener.location.href = window.opener.location.href; window.close();
Please note that this may cause problems if the parent page was produced as a result of POSTing a form.
Try this it may help other as well,,
`new = window.open(url);
new.focus();
check = setInterval(function() {
if (new.closed) {
window.location.reload(true)
}}, 1000);`

Categories