JSFiddle - React, Tailwind, and code Playground
by trixta
HTML
<script src="http://afarkas.github.io/webshim/js-webshim/minified/extras/modernizr-custom.js"></script>
<script src="http://afarkas.github.io/webshim/js-webshim/minified/polyfiller.js"></script>
<form action="#" class="ws-validate">
<div class="form-row">
<label for="bday">birthday</label>
<input id="bday" type="date" max="1995-12-31" required="" />
</div>
<div class="form-row">
<label for="bday2">birthday dynamic</label>
<input id="bday2" type="date" data-relmax="-18" required="" />
</div>
<div class="form-row">
<input type="submit" />
</div>
</form>
CSS
form {
margin: 10px auto;
max-width: 600px;
min-width: 220px;
}
.form-row {
padding: 5px 10px;
}
label {
display: block;
margin: 3px 0;
}
.form-row input {
width: 220px;
padding: 3px 1px;
}
JavaScript
webshims.setOptions('forms', {
iVal: {
sel: '.ws-validate'
}
});
//start polyfilling
webshims.polyfill('forms forms-ext');
$(function () {
$('input[data-relmax]').each(function () {
var oldVal = $(this).prop('value');
var relmax = $(this).data('relmax');
var max = new Date();
max.setFullYear(max.getFullYear() + relmax);
$.prop(this, 'max', $(this).prop('valueAsDate', max).val());
$.prop(this, 'value', oldVal);
});
});