Chorn Sokun's Weblog

Conquer inner fear, push it to the limit!

Brail Daily Use Macros #2

with 2 comments

Imagine you had to associate multiple skill to your “Profile”

Multiple skill

Suppose we have the following Profile & Skill class

class Profile {
  public virtual int Id { get; set; }
  public virtual string Name { get; set; }
  //.... other properties as necessary
  public virtual IList<Skill> Skills { get;set; }
}

// a lookup class per say
class Skill {
  public virtual int Id { get;set; }
  public virtual Profile { get; set; }
  public virtual string Title { get; set; }
}

Assume that we know how to apply AR attribute on these two class make it persist able to a database. The important thing is Profile has many Skills that all you have to concentrate on right now.

Ok ! today recipe is to generate UI with checkbox which allow user to tick and save the choices without any hassle. With the help of FormHelper method YES, WE CAN

<%
list = Form.CreateCheckboxFieldList("p.Skills", skills, {@text:'Title', @value:'Id'})
// we need a loop
for item in list:
%>
  ${list.Item()}  ${item.ToString()}
<%
end
%>

Don’t panic let me explain a bit ${list.Item()} will generate individual html checkbox where ${item.ToString()} will generate a label for each one.

Advertisements

Written by Chorn Sokun

March 16, 2009 at 5:00 pm

2 Responses

Subscribe to comments with RSS.

  1. Hello!
    Very Interesting post! Thank you for such interesting resource!
    PS: Sorry for my bad english, I’v just started to learn this language ;)
    See you!
    Your, Raiul Baztepo

    RaiulBaztepo

    March 29, 2009 at 4:44 am

  2. Hello ! :)
    I am Piter Kokoniz. oOnly want to tell, that I like your blog very much!
    And want to ask you: what was the reasson for you to start this blog?
    Sorry for my bad english:)
    Thank you!
    Your Piter Kokoniz, from Latvia

    PiterKokoniz

    April 8, 2009 at 5:52 am


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: