0
I wonder if there is any way to change the format of datepicker dynamically, using radio Buttons, but the way I’m trying is not working ...
HTML
<input id="periodo" name="periodo" type="text" placeholder="Período">
<input id="radioDDMM" type="radio" name="typePeriodo" checked data-type="dd/mm" />
<label for="radioDDMM">Dia/Mês</label>
<input id="radioMMYYYY" type="radio" name="typePeriodo" data-type="mm/yyyy" />
<label for="radioMMYYYY">Mês/Ano</label>
Jquery
$(document).ready(function () {
$('#periodo').datepicker({
format: "dd/mm",
startView: "days",
minViewMode: "days",
language: 'pt-BR',
endDate: '0m',
orientation: 'bottom',
autoclose: true
});
$("[name='typePeriodo']").on('change', function () {
var type = $(this).attr('data-type');
if (type == "dd/mm") {
$('#periodo').datepicker({
altFormat: "dd/mm",
startView: "days",
minViewMode: "days",
})
} else if (type == "mm/yyyy") {
$('#periodo').datepicker({
altFormat: "mm/yyyy",
startView: "months",
minViewMode: "months",
})
}
});
});
I’m not a web expert, but I think you’re going to need something that implements the "Observable" data Pattern. I think angular, or ko has it
– Leonardo Alves Machado