Commit c79d3ed9 authored by Stephane Glondu's avatar Stephane Glondu

Question editor: allow removing any answer

parent 814f8f50
......@@ -84,6 +84,16 @@ let createAnswer a =
u##size <- 60;
Dom.appendChild container t;
Dom.appendChild container u;
let btn_text = document##createTextNode (Js.string "Remove") in
let btn = Dom_html.createButton document in
let f _ =
container##parentNode >>= fun x ->
Dom.removeChild x container;
return ()
in
btn##onclick <- handler f;
Dom.appendChild btn btn_text;
Dom.appendChild container btn;
container
let createQuestion q =
......@@ -125,7 +135,7 @@ let createQuestion q =
let x = createAnswer a in
Dom.appendChild h_answers x)
q.q_answers;
(* buttons for adding/removing answers *)
(* button for adding answer *)
let x = Dom_html.createDiv document in
let b = Dom_html.createButton document in
let t = document##createTextNode (Js.string "Add an answer") in
......@@ -136,20 +146,6 @@ let createQuestion q =
b##onclick <- handler f;
Dom.appendChild b t;
Dom.appendChild x b;
let b = Dom_html.createButton document in
let t = document##createTextNode (Js.string "Remove last answer") in
let f _ =
let answers = h_answers##querySelectorAll (Js.string ".question_answer") in
let last_answer = answers##item (answers##length - 1) in
last_answer >>= fun x ->
x##parentNode >>= fun p ->
p##parentNode >>= fun q ->
ignore (q##removeChild (p));
return ()
in
b##onclick <- handler f;
Dom.appendChild b t;
Dom.appendChild x b;
Dom.appendChild container x;
(* horizontal rule *)
let x = Dom_html.createHr document in
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment