Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
bootstrap-multiselect
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
bootstrap-multiselect
Commits
439cf36f
Commit
439cf36f
authored
Feb 13, 2015
by
davidstutz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
onSelectAll option for #415.
parent
04bee6dd
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
115 additions
and
17 deletions
+115
-17
bootstrap-multiselect.js
dist/js/bootstrap-multiselect.js
+27
-16
index.html
index.html
+43
-0
bootstrap-multiselect.js
tests/spec/bootstrap-multiselect.js
+45
-1
No files found.
dist/js/bootstrap-multiselect.js
View file @
439cf36f
...
...
@@ -89,7 +89,7 @@
function
forEach
(
array
,
callback
)
{
for
(
var
index
=
0
;
index
<
array
.
length
;
++
index
)
{
callback
(
array
[
index
]);
callback
(
array
[
index
]
,
index
);
}
}
...
...
@@ -240,6 +240,12 @@
*/
onDropdownHidden
:
function
(
event
)
{
},
/**
* Triggered on select all.
*/
onSelectAll
:
function
()
{
},
buttonClass
:
'
btn btn-default
'
,
inheritClass
:
false
,
...
...
@@ -1004,8 +1010,9 @@
* If justVisible is true or not specified, only visible options are selected.
*
* @param {Boolean} justVisible
* @param {Boolean} triggerOnSelectAll
*/
selectAll
:
function
(
justVisible
)
{
selectAll
:
function
(
justVisible
,
triggerOnSelectAll
)
{
var
justVisible
=
typeof
justVisible
===
'
undefined
'
?
true
:
justVisible
;
var
allCheckboxes
=
$
(
"
li input[type='checkbox']:enabled
"
,
this
.
$ul
);
var
visibleCheckboxes
=
allCheckboxes
.
filter
(
"
:visible
"
);
...
...
@@ -1033,6 +1040,10 @@
return
$
.
inArray
(
$
(
this
).
val
(),
values
)
!==
-
1
;
}).
prop
(
'
selected
'
,
true
);
}
if
(
triggerOnSelectAll
)
{
this
.
options
.
onSelectAll
();
}
},
/**
...
...
@@ -1102,42 +1113,41 @@
* The provided data will be used to build the dropdown.
*/
dataprovider
:
function
(
dataprovider
)
{
var
optionDOM
=
""
;
var
groupCounter
=
0
;
var
tags
=
[];
// create empty array
var
$select
=
this
.
$select
.
empty
();
$
.
each
(
dataprovider
,
function
(
index
,
option
)
{
var
tag
;
var
$tag
;
if
(
$
.
isArray
(
option
.
children
))
{
// create optiongroup tag
groupCounter
++
;
tag
=
$
(
'
<optgroup/>
'
).
attr
({
$tag
=
$
(
'
<optgroup/>
'
).
attr
({
label
:
option
.
label
||
'
Group
'
+
groupCounter
});
forEach
(
option
.
children
,
function
(
subOption
)
{
// add children option tags
tag
.
append
(
$
(
'
<option/>
'
).
attr
({
$
tag
.
append
(
$
(
'
<option/>
'
).
attr
({
value
:
subOption
.
value
,
label
:
subOption
.
label
||
subOption
.
value
,
title
:
subOption
.
title
,
selected
:
!!
subOption
.
selected
}));
});
optionDOM
+=
'
</optgroup>
'
;
}
else
{
// create option tag
tag
=
$
(
'
<option/>
'
).
attr
({
else
{
$
tag
=
$
(
'
<option/>
'
).
attr
({
value
:
option
.
value
,
label
:
option
.
label
||
option
.
value
,
title
:
option
.
title
,
selected
:
!!
option
.
selected
});
tags
.
push
(
tag
);
}
$select
.
append
(
$tag
);
});
this
.
$select
.
empty
().
append
(
tags
);
this
.
rebuild
();
},
...
...
@@ -1201,6 +1211,7 @@
if
(
checkedBoxesLength
>
0
&&
checkedBoxesLength
===
allBoxesLength
)
{
selectAllInput
.
prop
(
"
checked
"
,
true
);
selectAllLi
.
addClass
(
this
.
options
.
selectedClass
);
this
.
options
.
onSelectAll
();
}
else
{
selectAllInput
.
prop
(
"
checked
"
,
false
);
...
...
index.html
View file @
439cf36f
...
...
@@ -1595,6 +1595,49 @@
});
});
<
/script
>
</pre>
</div>
</td>
</tr>
<tr>
<td>
<code>
onSelectAll
</code>
</td>
<td>
<p>
This function is triggered when the select all option is used to select all options. Note that this can also be triggered manually using the
<code>
.multiselect('selectAll')
</code>
method.
</p>
<div
class=
"example"
>
<script
type=
"text/javascript"
>
$
(
document
).
ready
(
function
()
{
$
(
'
#example-onSelectAll
'
).
multiselect
({
includeSelectAllOption
:
true
,
onSelectAll
:
function
()
{
alert
(
'
onSelectAll triggered.
'
);
}
});
});
</script>
<select
id=
"example-onSelectAll"
multiple=
"multiple"
>
<option
value=
"1"
>
Option 1
</option>
<option
value=
"2"
>
Option 2
</option>
<option
value=
"3"
>
Option 3
</option>
<option
value=
"4"
>
Option 4
</option>
<option
value=
"5"
>
Option 5
</option>
<option
value=
"6"
>
Option 6
</option>
</select>
</div>
<div
class=
"highlight"
>
<pre
class=
"prettyprint linenums"
>
<
script type=
"
text/javascript
">
$('#example-onSelectAll').multiselect({
includeSelectAllOption: true,
onSelectAll: function() {
alert('onSelectAll triggered.');
}
});
<
/script
>
</pre>
</div>
</td>
...
...
tests/spec/bootstrap-multiselect.js
View file @
439cf36f
...
...
@@ -407,6 +407,10 @@ describe('Bootstrap Multiselect "Dataprovider"', function() {
});
describe
(
'
Bootstrap Multiselect "Select All".
'
,
function
()
{
var
onSelectAllTriggered
=
false
;
var
onDeselectAllTriggered
=
false
;
beforeEach
(
function
()
{
var
$select
=
$
(
'
<select id="multiselect" multiple="multiple"></select>
'
);
...
...
@@ -419,7 +423,13 @@ describe('Bootstrap Multiselect "Select All".', function() {
$select
.
multiselect
({
buttonContainer
:
'
<div id="multiselect-container"></div>
'
,
includeSelectAllOption
:
true
,
selectAllValue
:
'
multiselect-all
'
selectAllValue
:
'
multiselect-all
'
,
onSelectAll
:
function
()
{
onSelectAllTriggered
=
true
;
},
onDeselectAll
:
function
()
{
onDeselectAllTriggered
=
true
;
}
});
});
...
...
@@ -524,6 +534,40 @@ describe('Bootstrap Multiselect "Select All".', function() {
expect
(
$
(
'
#multiselect-container input[value="multiselect-all"]
'
).
prop
(
'
checked
'
)).
toBe
(
false
);
});
it
(
'
Should trigger onSelectAll based on the change event.
'
,
function
()
{
expect
(
$
(
'
#multiselect option:selected
'
).
length
).
toBe
(
0
);
expect
(
$
(
'
#multiselect-container input[value="multiselect-all"]
'
).
prop
(
'
checked
'
)).
toBe
(
false
);
// Change all checkboxes except the select all one.
$
(
'
#multiselect-container input[value!="multiselect-all"]
'
).
prop
(
'
checked
'
,
true
);
$
(
'
#multiselect-container input[value!="multiselect-all"]
'
).
trigger
(
'
change
'
);
expect
(
$
(
'
#multiselect option:selected[value!="multiselect-all"]
'
).
length
).
toBe
(
99
);
// 100 options seleted including the select all.
expect
(
$
(
'
#multiselect option:selected
'
).
length
).
toBe
(
99
);
expect
(
$
(
'
#multiselect-container input[value="multiselect-all"]
'
).
prop
(
'
checked
'
)).
toBe
(
true
);
expect
(
onSelectAllTriggered
).
toBe
(
true
);
});
it
(
'
Should trigger onSelectAll based on the click event.
'
,
function
()
{
expect
(
$
(
'
#multiselect option:selected
'
).
length
).
toBe
(
0
);
expect
(
$
(
'
#multiselect-container input[value="multiselect-all"]
'
).
prop
(
'
checked
'
)).
toBe
(
false
);
$
(
'
#multiselect-container input[value!="multiselect-all"]
'
).
click
();
expect
(
$
(
'
#multiselect option:selected
'
).
length
).
toBe
(
99
);
expect
(
$
(
'
#multiselect-container input[value="multiselect-all"]
'
).
prop
(
'
checked
'
)).
toBe
(
true
);
expect
(
onSelectAllTriggered
).
toBe
(
true
);
});
it
(
'
Should trigger onSelectAll on function call.
'
,
function
()
{
$
(
'
#multiselect
'
).
multiselect
(
'
selectAll
'
,
true
,
true
);
expect
(
onSelectAllTriggered
).
toBe
(
true
);
});
afterEach
(
function
()
{
$
(
'
#multiselect
'
).
multiselect
(
'
destroy
'
);
$
(
'
#multiselect
'
).
remove
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment