Code Monkey home page Code Monkey logo

calender-date-picker's Introduction

Calender-date-picker

HTML CSS Vanilla Javascript Calendar / date picker / Selector with maximum and minimum date range and block certain days of the week

  1. In the html script, create divs where you want the calendar picker in the format
<div class="calendar inactive"> 
  <input id="calendarN-input" class="calendar-input " placeholder="mm/dd/yy" type="text" value="">
  <img id="cld-img" src="./img/calendar.png">
 </div> 

the N would have values of 1, 2, 3.... according to the number of calendars in the page the files can be changed to preffered images

  1. Link calendar.js to your to your page before your main js script i.e <script src="./calendar.js"></script>

then add event listeners on the divs in your main js script to implement the calendar i.e for a div with an id of calendar1-input:

var calendar1 = document.getElementById("calendar1-input").parentElement
calendar1.addEventListener('click', (e) =>{    
 if(e.target.classList.contains("cld-img")){
    constructPicker(e, minumumDate, maximumDate, "Blocked days")
 }             
}) // Set the minimum dates and maximum dates as indicated below

OR if they all have the same date range easily;

var calendars = Array.from(document.getElementsByClassName("calendar"))
calendars.forEach(calendar => {
   calendar.addEventListener('click', (e) =>{      
      if(e.target.id === "cld-img"){
         constructPicker(e, minumumDate, maximumdate, "blocked days")
      }             
   })  
})  

If minimum date is present date use getCurrentDateSte(), and "01-01-0001" for unspecified minimum date range else "mm-dd-yyyy" format Use ""N/A" for unlimited maximum date range else format "mm-dd-yyyy for blocked days of the week use the index(from Sunday as 1) of the days with spaces in between as strings. i.e to deactivate all Sundays and Wednesdays

 constructPicker(e, minumumDate, maximumdate, "1 4")
  1. Add the calendar.css content to your style sheet and images to your work folder and style to your satisfaction. Be sure to edit the "src" paths. Also pardon the default theme I'm not very good with colors

  2. Enjoy!!

*Note this uses the procedural pattern for simplicity *OOP pattern will come as an update

Feel free to contribute (especially to style, year and month/year picker too), leave comment, open issues if any and star if you love it.

calender-date-picker's People

Contributors

adavizethefirst avatar

Watchers

 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.