Skip to content

Instantly share code, notes, and snippets.

@joubertnel
Created December 20, 2011 17:11
Show Gist options
  • Save joubertnel/1502349 to your computer and use it in GitHub Desktop.
Save joubertnel/1502349 to your computer and use it in GitHub Desktop.
SproutCore isDefault button bound to whether a group hasFirstResponder status
// ==========================================================================
// Project: ReturnRouting - mainPage
// Copyright: @2011 My Company, Inc.
// ==========================================================================
/*globals ReturnRouting */
ReturnRouting.SelectView = SC.SelectView.extend({
/*
If the user presses the Return key, instead of showing the
SelectView's popup menu, we pass the event along so that the action
on the default button can be invoked.
*/
keyDown: function(evt) {
if (evt.keyCode === SC.Event.KEY_RETURN) {
evt.allowDefault();
return NO;
} else {
return sc_super();
}
}
});
// This page describes the main user interface for your application.
ReturnRouting.mainPage = SC.Page.design({
// The main pane is made visible on screen as soon as your app is loaded.
// Add childViews to this pane for views to display immediately on page
// load.
mainPane: SC.MainPane.design({
childViews: ['emailGroup', 'phoneGroup'],
emailGroup: SC.WellView.design({
layout: { left: 50, top: 50, right:50, height: 275 },
contentView: SC.View.design({
layout: { left:0, top:0, right:0, bottom:0 },
childViews: ['emailTypeSelector', 'emailInput', 'addButton'],
emailTypeSelector: ReturnRouting.SelectView.design({
items: ['Home', 'Work'],
layout: { left:10, top:10, width:100, height:30 },
acceptsFirstResponder: YES
}),
emailInput: SC.TextFieldView.design({
layout: { left:110, top:10, width:100, height:30 }
}),
addButton: SC.ButtonView.design({
layout: { left:10, top:50, width:60, height:30 },
target: 'ReturnRouting',
action: 'addEmailAddress',
title: 'Add Email',
isDefaultBinding: 'ReturnRouting.mainPage.mainPane.emailGroup.hasFirstResponder'
})
})
}),
phoneGroup: SC.WellView.design({
layout: { left: 50, top: 380, right:50, height: 275 },
contentView: SC.View.design({
layout: { left:0, top:0, right:0, bottom:0 },
childViews: ['phoneTypeSelector', 'phoneInput', 'addButton'],
phoneTypeSelector: SC.SelectView.design({
items: ['Mobile', 'Fixed'],
layout: { left:10, top:10, width:100, height:30 }
}),
phoneInput: SC.TextFieldView.design({
layout: { left:110, top:10, width:100, height:30 }
}),
addButton: SC.ButtonView.design({
layout: { left:10, top:50, width:60, height:30 },
target: 'ReturnRouting',
action: 'addPhone',
title: 'Add Phone',
isDefaultBinding: 'ReturnRouting.mainPage.mainPane.phoneGroup.hasFirstResponder'
})
})
})
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment