From cf79beba80387e9c94d365dadbedb04a3c241d6e Mon Sep 17 00:00:00 2001
From: Dani Palou <dani@moodle.com>
Date: Wed, 1 Aug 2018 14:54:46 +0200
Subject: [PATCH] MOBILE-2540 lesson: Fix more than one choice in single choice
 questions

---
 src/addon/mod/lesson/pages/player/player.html |  3 ++-
 src/directives/format-text.ts                 | 10 ++++++----
 2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/src/addon/mod/lesson/pages/player/player.html b/src/addon/mod/lesson/pages/player/player.html
index 8ec2f5d79..a6a2c73c6 100644
--- a/src/addon/mod/lesson/pages/player/player.html
+++ b/src/addon/mod/lesson/pages/player/player.html
@@ -37,7 +37,8 @@
                 </ion-item>
 
                 <!-- Question page. -->
-                <form *ngIf="question" ion-list [formGroup]="questionForm">
+                <!-- We need to set ngIf loaded to make formGroup directive restart every time a page changes, see MOBILE-2540. -->
+                <form *ngIf="question && loaded" ion-list [formGroup]="questionForm">
                     <ion-item-divider text-wrap color="light">
                         <core-format-text [component]="component" [componentId]="lesson.coursemodule" [text]="pageContent"></core-format-text>
                     </ion-item-divider>
diff --git a/src/directives/format-text.ts b/src/directives/format-text.ts
index acaed8032..c5a7ed346 100644
--- a/src/directives/format-text.ts
+++ b/src/directives/format-text.ts
@@ -536,10 +536,12 @@ export class CoreFormatTextDirective implements OnChanges {
                 // Do the iframe responsive.
                 if (iframe.parentElement.classList.contains('embed-responsive')) {
                     iframe.addEventListener('load', () => {
-                        const css = document.createElement('style');
-                        css.setAttribute('type', 'text/css');
-                        css.innerHTML = 'iframe {width: 100%;height: 100%;}';
-                        iframe.contentDocument.head.appendChild(css);
+                        if (iframe.contentDocument) {
+                            const css = document.createElement('style');
+                            css.setAttribute('type', 'text/css');
+                            css.innerHTML = 'iframe {width: 100%;height: 100%;}';
+                            iframe.contentDocument.head.appendChild(css);
+                        }
                     });
                 }
             }