MattHoneycutt / SpecsFor

SpecsFor is a light-weight Behavior-Driven Development framework that focuses on ease of use for *developers* by minimizing testing friction.
http://specsfor.com
MIT License
197 stars 70 forks source link

What is the recommended way of dealing with checkboxes (specifically MvcCheckboxList) #88

Closed RedX2501 closed 8 years ago

RedX2501 commented 8 years ago

When using MvcCheckBoxList (http://mvccbl.com/) the generated html code looks like:

<input id="PostedSelectedUsers0" name="PostedSelectedUsers" type="checkbox" value="074f4b80-51bc-4b2a-8579-c6c05d8c0293" />
<label for="PostedSelectedUsers0">Uname0 Surname0</label> &nbsp; 
<input id="PostedSelectedUsers1" name="PostedSelectedUsers" type="checkbox" value="355b7f56-1ea8-4ef2-b895-7fcb13717eca" />
<label for="PostedSelectedUsers1">Uname3 Surname3</label> &nbsp; 
<input id="PostedSelectedUsers2" name="PostedSelectedUsers" type="checkbox" value="3eb9995e-99e3-425a-b978-1409bdd61fb6" />
<label for="PostedSelectedUsers2">admin </label> &nbsp; 
<input id="PostedSelectedUsers3" name="PostedSelectedUsers" type="checkbox" value="4cd9d00d-a86d-43e7-b6e6-986a364a020f" />
<label for="PostedSelectedUsers3">Uname2 Surname2</label> &nbsp; 
<input id="PostedSelectedUsers4" name="PostedSelectedUsers" type="checkbox" value="de8409a9-2a95-4827-bf0b-515de543ab2f" />
<label for="PostedSelectedUsers4">Uname1 Surname1</label> &nbsp; 

(line breaks added by me for clarity)

This is inside a form and generated with @Html.CheckBoxListFor(m => m.PostedSelectedUsers, mm => mm.AllUsers, mm => mm.Id, mm => mm.DisplayName, mm => mm.Users)

Using FindFormFor<Controller>().Field(f => f.PostedSelectedUsers) fails because there is no input named PostedSelectedUsers.

Does SpecsFor.Mvc provide any facilities for handling this?

MattHoneycutt commented 8 years ago

There's nothing built-in for 3rd party extensions, but you could write your own extension method easily enough. It looks like the input is derived from the model property name, you'd just need to suffix it with the zero-based index of the item you wish to check.