@@ -86,6 +86,7 @@ protected function definition_inner($mform) {
8686 , ['rows ' => 10 ], $ this ->editoroptions );
8787 $ mform ->addElement ('html ' , '</div> ' );
8888
89+ /** Add repeated sample answer options along with the field for returned responses */
8990 $ mform ->addElement ('header ' , 'prompttester ' , get_string ('prompttester ' , 'qtype_aitext ' ));
9091
9192 $ answeroptions = ['maxlen ' => 50 , 'rows ' => 6 , 'size ' => 30 ];
@@ -95,6 +96,7 @@ protected function definition_inner($mform) {
9596 $ mform ->createElement ('textarea ' , 'sampleanswers ' , get_string ('sampleanswer ' , 'qtype_aitext ' ), $ answeroptions ),
9697 $ mform ->createElement ('textarea ' , 'sampleanswereval ' , get_string ('sampleanswereval ' , 'qtype_aitext ' ), $ evaloptions ),
9798 $ mform ->createelement ('button ' , 'sampleanswerbtn ' , get_string ('sampleanswerevaluate ' , 'qtype_aitext ' )),
99+ $ mform ->createElement ('submit ' , 'deletesample ' , 'Delete sample ' ),
98100 $ mform ->createElement ('html ' , '<hr/> ' ),
99101 ];
100102
@@ -165,10 +167,12 @@ protected function definition_inner($mform) {
165167 protected function get_sample_count () {
166168 if (isset ($ this ->question ->id )) {
167169 if (isset ($ this ->question ->options ->sampleanswers )) {
168- return count ($ this ->question ->options ->sampleanswers );
170+ if ($ this ->question ->options ->sampleanswer > 0 ) {
171+ return count ($ this ->question ->options ->sampleanswers );
172+ }
169173 }
170174 }
171- return 0 ;
175+ return 1 ;
172176 }
173177
174178 /**
@@ -195,6 +199,7 @@ protected function data_preprocessing($question) {
195199 $ question ->spellcheck = $ question ->options ->spellcheck ;
196200 // Make the count start from 0 like the repeat array elements.
197201 $ question ->sampleanswers = [];
202+ xdebug_break ();
198203 foreach ($ question ->options ->sampleanswers as $ sampleanswer ) {
199204 $ question ->sampleanswers [] = $ sampleanswer ->response ;
200205 }
0 commit comments