Checkbox Vue Component
Checkbox Vue component represents Checkbox component.
Checkbox Components
There are following components included:
f7-checkbox
Checkbox Properties
Prop | Type | Default | Description |
---|---|---|---|
<f7-checkbox> properties | |||
checked | boolean | Defines whether the checkbox input is checked or not | |
indeterminate | boolean | Defines whether the checkbox input is in indeterminate state or not | |
name | string number | Checkbox input name | |
value | string number boolean | Checkbox input value | |
disabled | boolean | Defines whether the checkbox input is disabled | |
readonly | boolean | Defines whether the checkbox input is readonly |
Checkbox Events
Event | Description |
---|---|
<f7-checkbox> events | |
change | Event will be triggered when checkbox state changed |
Checkboxes List
Checkboxes List is not a separate component, but just a particular case of using <f7-list>
, <f7-list-item>
.
<f7-list>
<!-- Additional "checkbox" prop to enable checkbox list item -->
<f7-list-item checkbox value="check_1" checked title="Checkbox 1"></f7-list-item>
<f7-list-item checkbox value="check_2" title="Checkbox 2"></f7-list-item>
</f7-list>
Checkbox v-model
v-model
is not supported on Checkbox vue component. Instead, just use the combination of checked
property and @change
event:
<template>
<f7-page>
<!-- With boolean value -->
<f7-checkbox :checked="jobIsDone" @change="jobIsDone = $event.target.checked"></f7-checkbox>
<!-- With array value -->
<f7-checkbox
value="banana"
:checked="fruits.indexOf('banana') >= 0"
@change="checkFruits"
></f7-checkbox>
<f7-checkbox
value="orange"
:checked="fruits.indexOf('orange') >= 0"
@change="checkFruits"
></f7-checkbox>
<f7-checkbox
value="apple"
:checked="fruits.indexOf('apple') >= 0"
@change="checkFruits"
></f7-checkbox>
</f7-page>
</template>
<script>
export default {
data() {
return {
jobIsDone: false,
fruits: [],
};
},
methods: {
checkFruits(event) {
const self = this;
const value = event.target.value;
if (event.target.checked) {
self.fruits.push(value);
} else {
self.fruits.splice(self.fruits.indexOf(value), 1);
}
},
},
};
</script>
Examples
Inline
<f7-block strong>
<p>Lorem <f7-checkbox name="checkbox-1"></f7-checkbox> ipsum dolor sit amet, consectetur adipisicing elit. Alias beatae illo nihil aut eius commodi sint eveniet aliquid eligendi <f7-checkbox name="checkbox-2" checked></f7-checkbox> ad delectus impedit tempore nemo, enim vel praesentium consequatur nulla mollitia!</p>
</f7-block>
Checkbox Group
<f7-list>
<f7-list-item checkbox title="Books" name="demo-checkbox" checked></f7-list-item>
<f7-list-item checkbox title="Movies" name="demo-checkbox"></f7-list-item>
<f7-list-item checkbox title="Food" name="demo-checkbox"></f7-list-item>
<f7-list-item checkbox title="Drinks" name="demo-checkbox"></f7-list-item>
</f7-list>
Indeterminate State
<f7-list>
<f7-list-item
checkbox
title="Movies"
name="demo-checkbox"
:checked="movies.length === 2"
:indeterminate="movies.length === 1"
@change="onMoviesChange"
>
<ul slot="root">
<f7-list-item
checkbox
title="Movie 1"
name="demo-checkbox"
value="Movie 1"
:checked="movies.indexOf('Movie 1') >= 0"
@change="onMovieChange"
/>
<f7-list-item
checkbox
title="Movie 2"
name="demo-checkbox"
value="Movie 2"
:checked="movies.indexOf('Movie 2') >= 0"
@change="onMovieChange"
/>
</ul>
</f7-list-item>
</f7-list>
export default {
data: function () {
return {
movies: ['Movie 1'],
};
},
methods: {
onMovieChange: function (e) {
var self = this;
var value = e.target.value;
var movies = self.movies;
if (e.target.checked) {
movies.push(value);
} else {
movies.splice(movies.indexOf(value), 1);
}
},
onMoviesChange: function (e) {
var self = this;
var movies = self.movies;
if (movies.length === 1 || movies.length === 0) {
self.movies = ['Movie 1', 'Movie 2'];
} else if (movies.length === 2) {
self.movies = [];
}
},
}
};
With Media Lists
<f7-list media-list>
<f7-list-item
checkbox
checked
name="demo-media-checkbox"
title="Facebook"
after="17:14"
subtitle="New messages from John Doe"
text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla sagittis tellus ut turpis condimentum, ut dignissim lacus tincidunt. Cras dolor metus, ultrices condimentum sodales sit amet, pharetra sodales eros. Phasellus vel felis tellus. Mauris rutrum ligula nec dapibus feugiat. In vel dui laoreet, commodo augue id, pulvinar lacus."
></f7-list-item>
<f7-list-item
checkbox
name="demo-media-checkbox"
title="John Doe (via Twitter)"
after="17:11"
subtitle="John Doe (@_johndoe) mentioned you on Twitter!"
text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla sagittis tellus ut turpis condimentum, ut dignissim lacus tincidunt. Cras dolor metus, ultrices condimentum sodales sit amet, pharetra sodales eros. Phasellus vel felis tellus. Mauris rutrum ligula nec dapibus feugiat. In vel dui laoreet, commodo augue id, pulvinar lacus."
></f7-list-item>
<f7-list-item
checkbox
name="demo-media-checkbox"
title="Facebook"
after="16:48"
subtitle="New messages from John Doe"
text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla sagittis tellus ut turpis condimentum, ut dignissim lacus tincidunt. Cras dolor metus, ultrices condimentum sodales sit amet, pharetra sodales eros. Phasellus vel felis tellus. Mauris rutrum ligula nec dapibus feugiat. In vel dui laoreet, commodo augue id, pulvinar lacus."
></f7-list-item>
<f7-list-item
checkbox
name="demo-media-checkbox"
title="John Doe (via Twitter)"
after="15:32"
subtitle="John Doe (@_johndoe) mentioned you on Twitter!"
text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla sagittis tellus ut turpis condimentum, ut dignissim lacus tincidunt. Cras dolor metus, ultrices condimentum sodales sit amet, pharetra sodales eros. Phasellus vel felis tellus. Mauris rutrum ligula nec dapibus feugiat. In vel dui laoreet, commodo augue id, pulvinar lacus."
></f7-list-item>
</f7-list>