From a47cf5e1bb0ecacda14dc09b33248680740c46b6 Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Tue, 17 Oct 2017 08:52:34 +0200 Subject: Don't accept incorrect correct answer indices --- assignment-6/multiplechoice.icl | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'assignment-6/multiplechoice.icl') diff --git a/assignment-6/multiplechoice.icl b/assignment-6/multiplechoice.icl index da6690d..b26d11c 100644 --- a/assignment-6/multiplechoice.icl +++ b/assignment-6/multiplechoice.icl @@ -73,11 +73,14 @@ where <<@ ApplyLayout (setUIAttributes (directionAttr Horizontal)) >>| teacherTask - cancelable :: (Task a) -> Task (Maybe a) | iTask a + cancelable :: (Task Question) -> Task (Maybe Question) cancelable t = t >>* - [ OnAction (Action "Cancel") $ always $ return Nothing - , OnAction (Action "Save") $ hasValue $ return o Just + [ OnAction (Action "Cancel") $ always $ return Nothing + , OnAction (Action "Save") $ ifValue isCorrect $ return o Just ] + where + isCorrect :: Question -> Bool + isCorrect q = q.Question.correct < length q.answers && q.Question.correct >= 0 append i = cancelable (enterInformation "New item" []) >>= ifJust (flip upd questions o insertAt i) edit (i,q) = cancelable (updateInformation "Edit item" [] q) >>= ifJust (flip upd questions o updateAt i) -- cgit v1.2.3