Arc Forumnew | comments | leaders | submitlogin
Checkbox
1 point by gidyn 6136 days ago | 6 comments
I'm trying to create a checkbox in Anarki. The code I've been trying to use is

  (attribute input checked opstring)
  
  (mac checkbox (name checked)
    `(gentag input
      ,(join `(type checkbox name ,name)
        (if checked `(checked ,checked)))))
but giving an error

  list->string: expects argument of type <list of character>; given (type checkbox ...
I suspect that this is related to my unfamiliarity with macros (and Arc in general). Any suggestions?


1 point by gidyn 6136 days ago | link

Found the source of the problem - line feeds seemed to be causing problems in the REPL.

  (mac checkbox (name checked) (join `(gentag input type 'checkbox name ,name) (if checked `(checked ,checked))))
works.

-----

3 points by skenney26 6136 days ago | link

You could also use a function.

Add this after opsel in html.arc:

  ; minimized attribute (use w/ selected, checked)
  (def opmin (key val) 
    `(if ,val (pr " " ',key)))
Add this to the list of attributes in html.arc:

  (attribute input checked opmin)
Add this wherever you like:

  (def checkbox (name (o checked))
    (gentag input type 'checkbox name name checked checked))
A test webpage:

  (defop checkboxes req
    (checkbox 1 t)
    (br)
    (checkbox 2))
This is the resulting source code:

  <input type=checkbox name="1" checked><br>
  <input type=checkbox name="2">

-----

1 point by gidyn 6135 days ago | link

Thank you. Exactly what I need.

-----

1 point by eds 6136 days ago | link

What OS and version of MzScheme are you on? I have had errors with line feeds before when pasting code from the clipboard on Windows, but those errors don't look the same as the ones you have encountered.

  arc> '(1
  2
  3)
  (1 2 3)
The above, typed from directly into the terminal, works fine, but the below, pasted from Notepad, results in the mysterious insertion of the symbol 'M into the list.

  arc> '(1
  2
  3)
  (1 2 M)
I posted a bug report at http://bugs.plt-scheme.org/query/?cmd=view&pr=9210, but they don't seem to have done anything about it in the last couple of months :( (although I suppose it is possible this bug doesn't occur in version 400).

-----

1 point by gidyn 6135 days ago | link

Windows XP MzScheme v352

My problems also occurred when copying and pasting, but not when (load) the file I was copying from. Another common error in this situation was undefined __M.

-----

1 point by eds 6135 days ago | link

I just tried v4.0.1 to see if they had fixed the bug... and it seems to still be there. I guess you just have to be careful about what you paste into the REPL under Windows. (Or use arc-mode in Emacs ;-)

-----