Sometimes you want to fire an action after hitting enter in a text field view. If this action is also a button,
you only have to set the isDefault property on the button to YES and the text field will automatically fire the action of the button.
But there are of course situations in which you don't have a button and still want something to happen,
as for example with a search field. In that case you can use the following code example.
The part in red is where it happens, you can make that work on any key and trigger whatever action you want.
searchField: SC.TextFieldView.design({
layout: { centerY: 0, height: 24, right: 120, width: 200 },
controlSize: SC.LARGE_CONTROL_SIZE,
fontWeight: SC.BOLD_WEIGHT,
hint: 'type your search here',
valueBinding: 'myApp.myController.searchTerm',
target: "myApp.pubmedController",
action: "newSearch",
keyDown: function(evt) {
sc_super(); // necessary to guarantee regular handling of keyDown events,
// want to avoid that this overwrite messes everything up
if (evt.keyCode === 13) {
// trigger the search after we've seen an "enter"
TwSprout.pubmedController.searchPubmed();
return YES;
} else {
return NO;
}
}
}),
Comments (0)
You don't have permission to comment on this page.