Fork me on GitHub

jquery-checkview

This jQuery plugin enables custom css styling of checkboxes and radiobuttons.

Features

Usage

Include dependencies

<script src="https://code.jquery.com/jquery-1.11.2.min.js"></script>
<script src="jquery.checkview.min.js"></script>

Provide markup

<label><input type="checkbox"/> Check me!</label>

Init checkview as follows:

$("input[type='checkbox'], input[type='radio']").checkview();

Set up your css. Take a look at the example styles:

.checkview {
  background-color: #FFFFFF;
  border: 1px solid #ACACAC;
  line-height: 1em;
}

.checkview .icon-ok {
  display: inline-block;
  background: url('http://cdn.dustball.com/tick.png') no-repeat center;
  background-size: contain;
  width: 1em;
  height: 1em;
}

Bootstrap Example

Include Bootstrap CSS:

<link href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet"/>

Provide Bootstrap Checkbox Markup:

<div class="checkbox">
  <label>
    <input type="checkbox"> Check me!
  </label>
</div>

Configure checkview with Bootstrap's button and icon components:

$(".checkbox input[type='checkbox']").checkview({
  wrapperClass: 'btn btn-default btn-xs',
  iconClass: 'glyphicon glyphicon-ok'
});

Options

NameDescriptionDefault
checkedClassCSS Class to indicate the checkview's statecheckview
iconClassIcon css classicon-ok
preventSubmitSpecifies whether to propagate pressing of enter keyfalse
wrapperClassContainer css classcheckview
wrapperTagContainer tag namespan

Methods

NameDescriptionReturn
getCheckedReturns the checkview's stateboolean
invalidateRefreshes the componentvoid
setChecked(bool)Sets the checkview's statevoid

Method example

Access plugin-instance and refresh

$("#checkview").data('checkview').refresh();