Page 1 of 1

modal window + update

Posted: Thu Oct 29, 2009 3:51 pm
by amoreno
Hi,

I am developing a component and i got stuck on that.

I have a component with a table view, on this table view I have an link on every item to edit it.
I did it using amodal window, I am able to click on edit, the nice modal window opens, I modify the data (the data is well modified) and then i close the window.

But the parent window is not actualised (if i refresh the window, then the data appears actualised),
but it should be a way of doing it actomatically isn't??

Can anyone help me?

What i did to get the modal window is the followind:

1.- put JHTML::_( 'behavior.modal'); on view.html.php
2.- use on the table: <a class="modal" id="popup" rel="{handler: 'iframe', size: {x: 650, y: 700}}" href="?option=com_mycomponent&tmpl=component&id=<?php echo $item->id; ?>"><img src='./images/M_images/edit.png' alt='View details' border=0></a>

thanks in advance,
Albert

Re: modal window + update

Posted: Thu Oct 29, 2009 7:36 pm
by dam-man
You need to do it with AJAX then. Otherwise you will not update the parent window. A modal box is AJAX but won't refrsh the parent window.

Re: modal window + update

Posted: Thu Oct 29, 2009 9:09 pm
by nailson_imgn
Trigger this js when you submit your modal window form. This shall reload the whole main page.

Code: Select all

window.parent.location.reload();
I don't tested myself, but it should be easy to adapt the code, if it don't work for what you want.

Re: modal window + update

Posted: Fri Oct 30, 2009 7:40 pm
by amoreno
Hi I tried to use it on the button
<button class="button validate" type="submit" class="validate" onClick="parent.window.location.reload()">
<?php echo JText::_('Save') ?>
</button>

and on the form by doing onSubmit, and both of them did not work !!

Where else could i place this reload to be effective?
Or what alternative could i apply?

NOTE: I also tried window.parent.location.reload().

Albert

Re: modal window + update

Posted: Tue Nov 03, 2009 11:38 am
by nailson_imgn
Try

Code: Select all

window.parent.parent.location.reload();

Re: modal window + update

Posted: Tue Nov 03, 2009 12:04 pm
by amoreno
no way !!

Re: modal window + update

Posted: Tue Nov 03, 2009 12:13 pm
by nailson_imgn
You're right. I just tested here and that doesn't work. However, I also tested window.parent.location.reload(); and it works fine for me, so it should work for you as well...

Re: modal window + update

Posted: Tue Nov 03, 2009 3:05 pm
by amoreno
It is strange, but it doesn't work for me !!

do you place it at the onClick or onSubmit on the submit button??

Re: modal window + update

Posted: Tue Nov 03, 2009 3:05 pm
by dam-man
Make sure you have also javascript tags around it.
Looks like you're writing javascript in PHP, that will not work

Re: modal window + update

Posted: Tue Nov 03, 2009 3:16 pm
by amoreno
Could you pass me some code to see how is it implemented ????

Re: modal window + update

Posted: Tue Nov 03, 2009 4:09 pm
by nailson_imgn
You can have this set at your main screen:

Code: Select all

<script type="text/javascript" >
function timedReload( time ){ setTimeout( "window.location.reload()", time ); }
</script>
And then, in your modal window you do like this:

Code: Select all

<script type="text/javascript" >
function submitForm(){
var canSubmit = false;
// Validate some fields
if( canSubmit ){
    // Test with different delays, so you can be sure that your 
    // form is submitted before tha main page gets reloaded
    window.parent.timedReload( 2000 );
    form.submit();
}
</script>
Note: if you don't manage to call the main window function like this, you can assign it to a hidden button and then fire its onclike event. Hope it helps...