Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deform2: Demo for fancy typeahead.js configuration #24

Open
wants to merge 1 commit into
base: deform2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions deformdemo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,42 @@ class Schema(colander.Schema):

return self.render_form(form)

@view_config(renderer='templates/form.pt',
name='autocomplete_extended_config')
@demonstrate('Autocomplete Input Widget (with extended configuration)')
def autocomplete_extended_config(self):
# Ripped-off from http://twitter.github.io/typeahead.js/examples/
prefetch_url = self.request.static_url(
'deformdemo:static/data/films_post_1960.json')
template = u'''
function (datum) {
var value = datum.value, year = datum.year;
return $("<div>").append(
$("<p><span class='glyphicon glyphicon-film'></span> </p>")
.append($("<strong>").text(value))
.append($("<span>").text(" — " + year))
).html();
}'''
widget = deform.widget.AutocompleteInputWidget(
datasets={
'name': 'best-picture-winners',
'prefetch': prefetch_url,
'template': deform.widget.literal_js(template),
}
)

class Schema(colander.Schema):
best_picture = colander.SchemaNode(
colander.String(),
validator=colander.Length(max=100),
widget=widget,
description='Select a movie')

schema = Schema()
form = deform.Form(schema, buttons=('submit',))

return self.render_form(form)

@view_config(renderer='json', name='autocomplete_input_values')
def autocomplete_input_values(self):
text = self.request.params.get('term', '')
Expand Down
Loading