Changes to SC.LabelView API

One of the oldest classes in SproutCore is the SC.LabelView.  This class simply displays strings of text (and optionally allows you to edit them with an inline editor).  Since I’m normalizing the SC API right now, this class is one of those that is simply too out of lockstep to maintain 100% compatibility in.  So I’m going to break the API.  I think you will see though that the new changes are well worth it.  Here is what you need to do to update your code:

The Old Way

In the past, to set the value of an SC.LabelView you set the content property.  For example, you might do something like this:


SC.LabelView.create({
  contentBinding: 'Contacts.detailController.fullName'
});

or if you were using the view helper:


<%= label_view :full_name, :bind => { :content => 'Contacts.detailController.fullName' } %>

If you wanted to set the content to a more complex object such as a record and extract a single value from it, you would use the property property to name the property key you wanted to check:


SC.LabelView.create({
   contentBinding: 'Contacts.contactsController.selection',
   property: 'fullName'
});

Or if you were using the view helper:


<%= label_view :full_name,
  :bind => { :content => 'Contacts.contactsController.selection' },
  :property => 'fullName' %>

The New Way

Now SC.LabelView follows the same convention used by all other views that include SC.Control (such as SC.ButtonView, etc.).  If you want to set the value of the label view, use the label property.  The example above becomes:


SC.LabelView.create({
  valueBinding: 'Contacts.detailController.fullName'
});

or with a view helper:


<%= label_view :full_name, :bind => { :value => 'Contacts.detailController.fullName' } %>

If you need to bind to a more complex object such as a record and you want to get a specific property, use the content property and set the name of the property key you want the label view to display using the contentValueKey:


SC.LabelView.create({
  contentBinding: 'Contacts.contactsController.selection',
  contentValueKey: 'fullName'
});

or with the view helper:


<%= label_view :full_name,
  :bind => { :content => 'Contacts.contactsController.selection' },
  :content_value_key => 'fullName' %>

That’s it.  Note that to use the :content_value_key in the helper above, you will need the new build tools.  If you are still using the old build tools, do the following instead:


<%= label_view :full_name,
  :bind => { :content => 'Contacts.contactsController.selection' },
  :properties => { :content_value_key => 'fullName' } %>

This change should basically bring you up to speed with the latest API.  Note that because of this shift, SC.LabelView can now be used as an item view in a collection.  The newly introduced SC.TextCellView has been merged into SC.LabelView and no longer exists as its own class.