General developer forum

Update question preview window from question_edit_form

 
Picture of Juergen Zimmer
Update question preview window from question_edit_form
 

Dear all, 


I'm developing a question type and in my question edit form the number of answers is flexible, similar to MC questions. Currently, I realise a change in the number of answers by submitting the form, after changing the number of options (a change via JS AJAX was very difficult because the editors have to be rendered, initialised, etc). 


My problem:

 When a question preview window is open, that window should be updated/reloaded after changing the number of options (i.e. after submitting the form and a page reload). 

My first try was to override the preview button/link and do
   var previewWindow = window.open(previewUrl, 'PreviewQuestion', 'height=620,width=750');

after the page reload I do 

   var existingWindow = window.open('', 'PreviewQuestion');

which is an undocumented javascript feature and doesn't work in FF Windows because it always just opens a new tab whenever the window does not exist. So I thought I try to keep track of whether the preview window is open or not. 

I tried to add a hidden field "previewopen" to the form and set it's value with JS. 

However, the value doesn't seem to be in the submitted data (maybe because it only takes the fields that are actually in the $question object?).

Has anyone an idea how I could implement the feature that the preview window always shows the current state of the question as it is stored in the database?

THanks

  Juergen 



 
Average of ratings: -
Tim at Lone Pine Koala Sanctuary
Re: Update question preview window from question_edit_form
Core developersDocumentation writersParticularly helpful MoodlersPlugin developers

If you just call Window.open with the preview URL, it will reload in the same window/tab. So, pass a real URL, not a blank one.

 
Average of ratings: -
Picture of Juergen Zimmer
Re: Update question preview window from question_edit_form
 

Sorry, maybe I'm missing something, but if I put this in the Javascript that is loaded with my question edit page then preview will always be opened. The problem I have is determining whether the preview had been open before the 'update' button was pressed and the page was reloaded. 

Maybe this explains better, why I did what I did:

https://medium.com/@bluepnume/every-known-way-to-get-references-to-windows-in-javascript-223778bede2d

under "Existing Popup Window".

 
Average of ratings: -
Picture of Juergen Zimmer
Re: Update question preview window from question_edit_form
 

OK, in a session cookie in window.sessionStorage I can store the fact that the preview is open. Now the problem is to delete the cookie when the user closes the preview window...

 
Average of ratings: -
Tim at Lone Pine Koala Sanctuary
Re: Update question preview window from question_edit_form
Core developersDocumentation writersParticularly helpful MoodlersPlugin developers
Ah! Sorry. I did not think fo that.
 
Average of ratings: -