How to check a box

51 views
Skip to first unread message

Pierre-Henry Perret

unread,
Jul 14, 2012, 5:09:50 PM7/14/12
to enf...@googlegroups.com

We can get the checked state of a box with the dom function .-checked 

But is it possible to make a box checked ?

Sort of .-setChecked true/false 


Creighton Kirkendall

unread,
Jul 15, 2012, 5:36:31 PM7/15/12
to enf...@googlegroups.com

You should be able to use "set!"  (fn [node] (set! (.-checked node) true))

CK

Pierre-Henry Perret

unread,
Jul 16, 2012, 4:30:42 AM7/16/12
to enf...@googlegroups.com
Thanks Creighton,

but this doesn't do nothing: no error, no checked toggle...
______________

___________________

Pierre-Henry Perret

unread,
Jul 16, 2012, 4:59:25 AM7/16/12
to enf...@googlegroups.com
In fact when I evaluate thie expr at the repl:
_____________________
(em/at js/document ["ul > li > .view > input"] (set! (.-checked %) true))
____________________________

I get
_____________
#<TypeError: Object true has no method 'call'>
____________________

Pierre-Henry Perret

unread,
Jul 16, 2012, 6:48:30 AM7/16/12
to enf...@googlegroups.com
If I do
______________
 (em/at js/document ["ul > li > .view > #check"] (em/set-attr :checked "checked"))
______________________

the :checked attr is effectively set to "checked", but the toglle checkbox doesnt change.

Creighton Kirkendall

unread,
Jul 16, 2012, 9:07:29 AM7/16/12
to enf...@googlegroups.com

Use set-prop instead of set-attr.  It another transform.  Sorry for the short messages only have my phone on me.

CK

Pierre-Henry Perret

unread,
Jul 16, 2012, 9:29:16 AM7/16/12
to enf...@googlegroups.com
It seems that em/set-prop is not defined...

Pierre-Henry Perret

unread,
Jul 16, 2012, 12:27:11 PM7/16/12
to enf...@googlegroups.com
After all, the checked state of the radio button is a properties ( we can see that in the live dom in chrome for instance)
So something like:
___________________________
(em/at js/document ["ul > li > .view > input"] #(em/set-attr % :properties {:checked true}))
_________________________________

should work... but It doesn't. So the question is Why is it not so simple ?

Creighton Kirkendall

unread,
Jul 16, 2012, 12:48:24 PM7/16/12
to enf...@googlegroups.com

That is what set-prop was designed for.  What version of enfocus are you using.

CK

Pierre-Henry Perret

unread,
Jul 16, 2012, 1:05:28 PM7/16/12
to enf...@googlegroups.com

I use enfocus as a git dependencies, commit 2eb2aaf78fe9d73eb3ad8094c5b5fe31b7366c46

Pierre-Henry Perret

unread,
Jul 18, 2012, 4:51:08 PM7/18/12
to enf...@googlegroups.com
Hi Creighton,

Which version that contains the set-prop macro should I use ?

Creighton Kirkendall

unread,
Jul 18, 2012, 6:49:35 PM7/18/12
to enf...@googlegroups.com

It seems that I left set-prop out if the base transforms.  This was not intentional and will be fixed this weekend when i get back from vacation.   In the mean time here is a custom transform to do what you need.

(defn set-checked []
  (ef/chainable-standard
     (fn [node] (set! (.-checked node) true))))

C K

Dan Campbell

unread,
Sep 14, 2015, 4:33:32 PM9/14/15
to Enfocus
Related to this (from a hundred years ago), is there a direct way to find out which radio button in a group is checked?  That is, returning the id of the check button?

So, if you had

<input type="radio" id="rb_Grp01_01" name="rb_Grp01" value="on" checked style="position:absolute;left:266px;top:280px;z-index:21;" tabindex="50" title="rb_Grp01_01">
<input type="radio" id="rb_Grp01_02" name="rb_Grp01" value="on" style="position:absolute;left:298px;top:280px;z-index:22;" tabindex="55" title="rb_Grp01_02">
<input type="radio" id="rb_Grp01_03" name="rb_Grp01" value="on" style="position:absolute;left:329px;top:280px;z-index:23;" tabindex="60" title="rb_Grp01_03">


, you would want to return the rb_Grp01_01 id.

ckirkendall

unread,
Sep 15, 2015, 4:38:02 PM9/15/15
to Enfocus
Dan,
The easiest way is to use the read-form-input extractor defined here: https://ckirkendall.github.io/enfocus-site/#doc-extract.  

Dan Campbell

unread,
Sep 15, 2015, 5:26:17 PM9/15/15
to enf...@googlegroups.com
Thanks, Ckirkendall.

Yep, I've been looking at the docs, and am probably interpreting them wrong.

So for examples,


Using the specific radio button id works fine:

( ef/at [ :#btn_ShowRadioButton_Status ] ( ev/listen :click #( js/alert ( ef/from "#rb_Grp01_01" ( ef/get-prop :checked )))))
returns true
, as expected.

( ef/at [ :#btn_ShowRadioButton_Status ] ( ev/listen :click #( js/alert  ( ef/from "#rb_Grp01_01" ( ef/read-form-input )))))
return on
, as expected.


But changing to the group name, instead of the button name, in order to try to retrieve the selected button:

( ef/at [ :#btn_ShowRadioButton_Status ] ( ev/listen :click #( js/alert  ( ef/from "#rb_Grp01" ( ef/read-form-input )))))        
returns null, whatever radio button is selected.        


( ef/at [ :#btn_ShowRadioButton_Status ] ( ev/listen :click #( js/alert  ( ef/from "#rb_Grp01" ( ef/filter :checked ( ef/get-prop :value ))))))
returns null


The problem is that the group is identified by the name rb_Grp01, rather than the id.




--

---
You received this message because you are subscribed to a topic in the Google Groups "Enfocus" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/enfocus/c87sFLOrhPQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to enfocus+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Creighton Kirkendall

unread,
Sep 15, 2015, 5:41:55 PM9/15/15
to Enfocus

Dan,
These are css3 selectors so to select an item by an attribute like name.  You need a selector like "[name='...']" vs "#..."

You received this message because you are subscribed to the Google Groups "Enfocus" group.
To unsubscribe from this group and stop receiving emails from it, send an email to enfocus+u...@googlegroups.com.

Dan Campbell

unread,
Sep 15, 2015, 5:45:59 PM9/15/15
to enf...@googlegroups.com
Great, I'll try it, thanks.

Reply all
Reply to author
Forward
0 new messages