Skip to content
This repository has been archived by the owner on Apr 3, 2023. It is now read-only.

Commit

Permalink
Add checkbox option for multiple selectbox
Browse files Browse the repository at this point in the history
  • Loading branch information
rokburgar committed Mar 10, 2015
1 parent 6de4bc0 commit fd05a17
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
13 changes: 13 additions & 0 deletions demo/index.html
Expand Up @@ -305,6 +305,19 @@ <h3>Select boxes</h3>
<option value="10">Ten</option>
</select>

<select class="reform-selectbox reform-pure" multiple data-showcheckbox="true" data-title="Also add checkboxes">
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
<option value="4">Four</option>
<option value="5">Five</option>
<option value="6">Six</option>
<option value="7">Seven</option>
<option value="8">Eight</option>
<option value="9">Nine</option>
<option value="10">Ten</option>
</select>

<select class="reform-selectbox reform-pure" title="I feel empty inside"></select>

<select class="reform-selectbox reform-pure" title=""></select>
Expand Down
8 changes: 7 additions & 1 deletion less/floater_abstract.less
Expand Up @@ -23,7 +23,13 @@
.ellipsis;
padding : @paddingVertical @paddingHorizontal;
cursor : pointer;


.reform-checkbox-fake {
height : @fontSize;
width : @fontSize;
margin-right : @fontSize;
}

&.hover {
background : @hoverBackgroundColor;
color : @hoverFontColor;
Expand Down
12 changes: 12 additions & 0 deletions src/selectbox_abstract.coffee
Expand Up @@ -11,6 +11,8 @@ class SelectBoxAbstract
fakeClass : 'reform-selectbox-fake'
}, options

$.extend @options, @orig.data()

# Don't do this twice
return if @orig.is '.reformed'

Expand Down Expand Up @@ -164,6 +166,16 @@ class SelectBoxAbstract
$item.attr 'title', $option.attr 'title'
$item.attr 'value', $option.val()

if @options.showcheckbox and @orig.is '[multiple]'
checkboxOptions =
type: 'checkbox'
class: 'reform-checkbox'

checkboxOptions.checked = 'checked' if $option.is ':selected'
checkboxOptions.checked = 'disabled' if $option.is ':disabled'

$item.append($('<input>', checkboxOptions))

$item.append @createItemContent $option

# Disable selected item, add values in @listMultiple
Expand Down

0 comments on commit fd05a17

Please sign in to comment.