Giter Club home page Giter Club logo

ractive-decorators-datepicker's Introduction

Ractive.js datepicker decorator plugin

This plugin is a decorator for vanillajs-datepicker.

Find more Ractive.js plugins at ractive.js.org/resources/#plugins/

See the demo here.

Usage

Load the plugin.

<!-- on Browser: -->
<!-- • vanillajs-datepicker is expected to be loaded before the plugin -->
<!-- • the plugin is exposed to global as 'datepickerDecorator' -->
<script src="https://cdn.jsdelivr.net/npm/ractive"></script>
<script src="https://cdn.jsdelivr.net/gh/mymth/[email protected]/dist/ractive-decorators-datepicker.js"></script>
// on Node.js:
// • the plugin imports vanillajs-datepicker internally
import Ractive from 'ractive';
import datepickerDecorator from 'ractive-decorators-datepicker';

Make the decorator available.

// to all Ractive instances
Ractive.decorators.datepicker = datepickerDecorator;

// to a single instance
var ractive = new Ractive({
    el: '#container',
    template: template,
    decorators: {
        datepicker: datepickerDecorator,
    },
});

// to all instaces of RactiveDatepicker
var RactiveDatepicker = Ractive.extend({
    decorators: {
        datepicker: datepickerDecorator,
    },
})

Set the as-datepicker attribute to the input tag (for single date) or input-daterange class element (for date range) you want to use the decorator.

<!-- single date input -->
<input type="text" as-datepicker value="{{date}}">

<!-- date range -->
<div class="input-group" as-datepicker>
    <input type="text" class="form-control" value="{{startDate}}">
    <span class="input-group-text">to</span>
    <input type="text" class="form-control" value="{{endDate}}">
</div>

Using types

Customizing the default type

You can set your initialize options for bootstrap-datepicker to datepickerDecorator.types.default.

datepickerDecorator.types.default = {
    autohide: true,
    clearButton: true
};

Adding types

You can also use multiple types of bootstrap-datepicker elements. To use additional types, first, add new types to datepickerDecorator.types with their initialize options.

datepickerDecorator.types.todayButton = {
    todayButton: true,
    todayHighlight: true
};
datepickerDecorator.types.multi = {
    maxNumberOfDates: 3,
};

Then set the type name to the as-datepicker attribute.

Note: type name must be quoted so that the decorator can take it as a literal.

<input type="text" as-datepicker="'todayButton'" value="{{date}}">

Using internal date format

The plugin allows you to use different date formats between datepicker UI and internal data. To use it, set a date format to datepickerDecorator.internalFormat.

datepickerDecorator.internalFormat = 'yyyy-mm-dd';

License

Copyright (c) 2016 Hidenao Miyamoto. Licensed MIT

ractive-decorators-datepicker's People

Contributors

mymth avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.