How to use RadioNodeList?

2,064 views
Skip to first unread message

Llion Jones

unread,
Jan 29, 2013, 6:49:43 PM1/29/13
to mi...@dartlang.org
I was advised to try asking this here after trying dart-discuss. Someone suggested that I'm even misunderstanding the point of this object. What I understand this class to do is allow me to assign a List of radio input nodes to it and then just look at RadioNodeList.value to see which radio button is selected.

I use Dart at home to play about with developing websites and am having some difficulties working out how to use RadioNodeList. I am sad to say I spent quite a while with this, fighting against the code and searching the web for answers only to give up and writing my own function to determine the value of the selected radio button. It might be to do with the fact that I am new to web dev and so am not migrating to Dart from javascript and am not familiar with the DOM model. Regardless, it is non-obvious how to use this object. There is no constructor or factory methods, using the internal constructor crashes my page and trying to assign lists of nodes to the object causes a type error (as I would expect, but I was trying everything). Could someone show me how to use this class and the corresponding HTML code, it has been annoying me all weekend.

Any help is most appreciated,

Llion

Timothy Armstrong

unread,
Jan 29, 2013, 9:10:37 PM1/29/13
to mi...@dartlang.org
I don't know anything about RadioNodeList, but if you have a set of radio buttons:

<input type="radio" name="choice" value="1">One<br/>
<input type="radio" name="choice" value="2">Two<br/>
<input type="radio" name="choice" value="3">Three<br/>

Then you can determine the value of the selection in Dart with:

query('input[type=radio][name=choice]:checked').value

The downside to this is that if none of them are checked, then the query will return null. But as long as you check for that case, you should be good.

--
Timothy


--
Consider asking HOWTO questions at Stack Overflow: http://stackoverflow.com/tags/dart
 
 

Matthew Butler

unread,
Jan 30, 2013, 9:24:26 AM1/30/13
to mi...@dartlang.org
I've not had a chance to play with it yet myself, however, it appears that a RadioNodeList is not something you create but rather a return value[1][2]. In particular when you do something similar to: Again I have not tried this yet myself but just based on the information I was able to locate, this is how it should work* (A RadioListNode should only be returned by an HTMLFormCollection/HTMLFormControlsCollection).

var myForm = query('form#myForm');
var myRadioList = myForm.queryAll('input[name=radioName]');


myRadioList
.value; // == first checked item

*: It's also possible it may not be implemented yet and instead just return a NodeList.

Matt
Reply all
Reply to author
Forward
0 new messages