Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML5 input type=date: Can I open/close the date picker with JavaScript?

I am trying to customise the HTML5 input type="date" element. I want to add a separate button clicking which will toggle visibility of the date picker dropdown. I couldn't find any info on this. Any help greatly appreciated!

enter image description here

like image 680
Aniket Suryavanshi Avatar asked Oct 16 '14 20:10

Aniket Suryavanshi


People also ask

Are there any style options for the HTML5 date picker?

Currently, there is no cross browser, script-free way of styling a native date picker.

Which HTML5 attributes can be used with HTML5 date input type to limit date selection?

The max attribute specifies the maximum value (date) for a date field. Tip: Use the max attribute together with the min attribute to create a range of legal values. Tip: To set or return the value of the min attribute, use the min property.

How do you restrict date input in HTML?

jQuery codegetFullYear(); if(month < 10) month = '0' + month. toString(); if(day < 10) day = '0' + day. toString(); var maxDate = year + '-' + month + '-' + day; $('#txtDate'). attr('max', maxDate); });

How do you handle input type date?

<input> elements of type="date" create input fields that let the user enter a date, either with a textbox that validates the input or a special date picker interface. The resulting value includes the year, month, and day, but not the time. The time and datetime-local input types support time and date+time input.


1 Answers

Here is Solution I made using CSS.

* {
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
}

.exmp-wrp {
    margin-top: 100px;
    position: relative;
    width: 200px;
}

.btn-wrp {
    border: 1px solid #dadada;
    display: inline-block;
    width: 100%;
    position: relative;
    z-index: 10;
}

.btn-clck {
    border: none;
    background: transparent;
    width: 100%;
    padding: 10px;
}

.btn-clck::-webkit-calendar-picker-indicator {
    right: -10px;
    position: absolute;
    width: 78px;
    height: 40px;
    color: rgba(204, 204, 204, 0);
    opacity: 0
}

.btn-clck::-webkit-inner-spin-button {
    -webkit-appearance: none;
}
.btn-clck::-webkit-clear-button {
    margin-right:75px;
 }
.btn {
    height: 100%;
    background: #fda200;
    border: none;
    color: #fff;
    padding: 13px;
    position: absolute;
    right: 0;
    top: 0;
}
<div class="exmp-wrp">
  <div class="btn-wrp">
    <input type="date" class="btn-clck"/>
  </div>
  <button class="btn">Click me</button>
</div>
like image 63
Yashwanth Gurrapu Avatar answered Oct 09 '22 15:10

Yashwanth Gurrapu