Welcome to Manicprogrammer Sign in | Join | Help

Stormwind.Accuracy - Part 4

Well, continuing the saga I came to the RadioButtons. These are quite tricky, since RadioButtons are elements that have different Ids, same names and, as I'll show, weird values.

If you are just doing your own HTML inputs then you can specify all that stuff and Accuracy would work fine. But I want to analyze two common approaches in WebForms here: RadioButton Web Control and RadioButtonList Web Control.

RadioButtonList Web Control

Well, apparently RadioButtonList renders pretty good HTML, with the values you specified and all, so all you have to do in order to fill it is:

   1:  I.Select("My Radio Button Name").RadioButton.WithValueOf("Any given value")

That's pretty simple, huh? Well there's a lot of magic happening behind the scenes here, hehehe.

Several RadioButton Web Controls sharing the same GroupName

Now this one is trickier, because when you do that this is what WebForms renders:

   1:  <input id="rdbTestOption1" type="radio" name="rdbTestOptions2" value="rdbTestOption1" /><label for="rdbTestOption1">Test1</label>
   2:  <input id="rdbTestOption2" type="radio" name="rdbTestOptions2" value="rdbTestOption2" /><label for="rdbTestOption2">Test2</label>
   3:  <input id="rdbTestOption3" type="radio" name="rdbTestOptions2" value="rdbTestOption3" /><label for="rdbTestOption3">Test3</label>
   4:  <input id="rdbTestOption4" type="radio" name="rdbTestOptions2" value="rdbTestOption4" /><label for="rdbTestOption4">Test4</label>

You can spot the issue right there, can't you? WebForms won't allow you to have custom-values. It just assigns the same string as in Id to the Value attribute. Now, you can change the value yourself, but I'd really feel like it's hacking. You don't want to mess with good ol' WebForms, now do you? So I had to implement a way for you to map the "fake values" to expected values.

So now you can register these RadioButtons in your Page class like this:"

   1:  Register.RadioButton("Test Options 2").WithValueMappingsOf(
   2:          "1", "rdbTestOption1",
   3:          "2", "rdbTestOption2",
   4:          "3", "rdbTestOption3",
   5:          "4", "rdbTestOption4"
   6:      );

This way you can still use the same WithValueOf construct as in the above item.

Conclusion

Well, I still have to manage the I.See("My Radio Button Name").RadioButton.HasValueOf("some value") construct, and apply the same concept to checkboxes. I'll be blogging about it in the next days.

#139

Published Monday, March 24, 2008 11:44 AM by heynemann

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

No Comments


Enter the text you see in the image:

Leave a Comment

(required) 
required 
(required)