@@ -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,13 +96,16 @@ 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 ' , 'delete ' , 'Delete sample ' ,0 ),
98100 $ mform ->createElement ('html ' , '<hr/> ' ),
99101 ];
100102
101103 $ repeateloptions = [];
102104 $ mform ->setType ('sampleanswereval ' , PARAM_CLEANHTML );
103105 $ mform ->setType ('optionid ' , PARAM_INT );
104106 $ samplecount = $ this ->get_sample_count ();
107+ $ mform ->registerNoSubmitButton ('delete ' );
108+
105109 $ this ->repeat_elements (
106110 $ repeatarray ,
107111 $ samplecount ,
@@ -114,6 +118,7 @@ protected function definition_inner($mform) {
114118 'delete ' ,
115119 );
116120
121+
117122 $ mform ->setType ('option ' , PARAM_CLEANHTML );
118123
119124 $ mform ->addElement ('header ' , 'responseoptions ' , get_string ('responseoptions ' , 'qtype_aitext ' ));
@@ -165,10 +170,12 @@ protected function definition_inner($mform) {
165170 protected function get_sample_count () {
166171 if (isset ($ this ->question ->id )) {
167172 if (isset ($ this ->question ->options ->sampleanswers )) {
168- return count ($ this ->question ->options ->sampleanswers );
173+ if (count ($ this ->question ->options ->sampleanswers ) > 0 ) {
174+ return count ($ this ->question ->options ->sampleanswers );
175+ }
169176 }
170177 }
171- return 0 ;
178+ return 1 ;
172179 }
173180
174181 /**
@@ -195,6 +202,7 @@ protected function data_preprocessing($question) {
195202 $ question ->spellcheck = $ question ->options ->spellcheck ;
196203 // Make the count start from 0 like the repeat array elements.
197204 $ question ->sampleanswers = [];
205+ xdebug_break ();
198206 foreach ($ question ->options ->sampleanswers as $ sampleanswer ) {
199207 $ question ->sampleanswers [] = $ sampleanswer ->response ;
200208 }
0 commit comments