field: SC.SelectFieldView.design({
layout: { width: 200, height: 22, right: 3, centerY: 0 },
objects: [
{name:'For 3 Seconds', value:'3seconds'},
{name:'Until the browser is closed', value:'closeBrowser'},
{name:'For 1 year', value:'1year'}
],
nameKey: 'name',
valueKey: 'value',
acceptsFirstResponder: function() {
return this.get('isEnabled');
}.property('isEnabled'),
isEnabledBinding: SC.Binding.from("LoginLogoutSample.loginPageController.isLoggingIn")
.bool()
.transform(function(value, isForward) {
return !value;
}),
valueBinding: 'LoginLogoutSample.loginPageController.rememberMe'
})
objects is an array of name (text to show to the user) and value (code to store in the database) pairs.
nameKey specifies the name of the property that contains the text that to show the user.
valueKey specifies the name of the property that contains the value to store.
For some reason, I could not tab onto the rendered select control (i.e. navigate using the keyboard and clicking the TAB key).
I found that you have to set acceptsFirstResponder. The sproutcore framework needs this function to be set before it will consider that a field is able to receive focus from the TAB key. TextFieldView has it but for some reason, SelectFieldView does not. I’ve just copied the above code from TextFieldView.
Hi,
I am new to SproutCore. Could you please tell me how can I hangle the selection change event for SelectFieldView. I want to display an alert for selected item
Add this to the controller:
rememberMeDidChange: function() {
alert(this.get(‘rememberMe’));
}.observes(‘rememberMe’)
It observes the rememberMe property and fires everytime it changes.