Skip to content
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
5 changes: 4 additions & 1 deletion client/document_view.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Template._houston_document_field.helpers
field_is_id: -> @name is '_id'
document_id: -> Houston._session('document_id')
has_type: -> Houston._INPUT_TYPES[@type]?
is_checkbox: -> Houston._INPUT_TYPES[@type] == 'checkbox'
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It turns out that this is not necessary - see below for why.

input_type: -> Houston._INPUT_TYPES[@type]

get_collection = -> Houston._get_collection(Houston._session('collection_name'))
Expand All @@ -31,7 +32,9 @@ Template._houston_document_view.events
for field in $('.houston-field')
field_name = field.name.split(' ')[0]
unless field_name is '_id'
update_dict[field_name] = Houston._convert_to_correct_type(field_name, field.value,
val = field.value
val = field.checked if field.type is 'checkbox'
update_dict[field_name] = Houston._convert_to_correct_type(field_name, val,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the right place to do the conversion is actually inside of _convert_to_correct_type, not here. You might need to pass field instead of field.value so you can extract field.checked, though.

get_collection())
Houston._call("#{Houston._session('collection_name')}_update",
Houston._session('document_id'), $set: update_dict)
Expand Down
9 changes: 7 additions & 2 deletions client/document_view.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,13 @@ <h1>{{name}}
value="{{ value }}" readonly>
{{else}}
{{#if has_type}}
<input type="{{ input_type }}" class="houston-field form-control"
name="{{ name_id }}" value="{{ value }}"/>
{{#if is_checkbox}}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I rewrote & tested this by adding both a checked and a value to each input, and it turned out to work pretty well. I don't think we need duplicate code here.

<input type="{{ input_type }}" class="houston-field form-control"
name="{{ name_id }}" checked="{{ value }}"/>
{{else}}
<input type="{{ input_type }}" class="houston-field form-control"
name="{{ name_id }}" value="{{ value }}"/>
{{/if}}
{{else}}
<textarea class="houston-field form-control" name="{{ name_id }}">{{ value
}}</textarea>
Expand Down