With some information passed by the author through the chat, we arrive at a code with the expected result by the same:
Javascript:
$(document).ready(function () {
//Data atual
var current = new Date();
//Somará 30 dias
var aux = new Date(current.getFullYear(), current.getMonth(), current.getDate() + 30);
if (aux.getDay() != 1) {
var nextMonth = new Date(aux.getFullYear(), aux.getMonth() + 1, 1);
var days = Math.floor((nextMonth - aux) / (1000 * 60 * 60 * 24))
if (days < 7) current = new Date(aux.getFullYear(), aux.getMonth(), aux.getDate() + days);
else current = aux;
} else {
current = aux;
}
$("#data-inicio").datepicker({
minDate: current,
dateFormat: 'dd/mm/yy', //Formato da data
beforeShowDay: function (date) {
return [date.getDay() == 1, ""]
},
onSelect: function (selectedDate) {
//Limpamos a segunda data, para evitar problemas do usuário ficar trocando a data do primeiro datepicker e acabar burlando as regras definidas.
$.datepicker._clearDate($("#data-retorno"));
//Aqui está a "jogada" para somar os 7 dias para o próximo datepicker.
var data = $.datepicker.parseDate('dd/mm/yy', selectedDate);
data.setDate(data.getDate('dd/mm/yy') + 7); //Soma 7 dias a data atual
$("#data-retorno").datepicker("option", "minDate", data); //Aplica a data
}
});
//Segundo datepicker
$("#data-retorno").datepicker({
dateFormat: 'dd/mm/yy', //Formatação
onClose: function (selectedDate) {
$("#data-inicio").datepicker("option", "maxDate", selectedDate);
},
beforeShowDay: function (date) {
return [date.getDay() == 5, ""]
}
});
});
HTML for example:
<input type="text" id="data-inicio" name="data-inicio" />
<input type="text" id="data-retorno" name="data-retorno" />
In operation:
https://jsfiddle.net/ddw8ya41/6/
You want this feature when the user changes the date or when the page loads?
– Sergio
the variable
dateObjetc
is with the value of a date selected from another datepicker, but also, when I try to do another datepicker based on the date of that variable, nothing happens.– Michel Henriq
Is it anything like that? https://jsfiddle.net/ddw8ya41/ OBS: Not implemented the sum of 7 days yet. I just wonder if the idea is on track...
– Rafael Withoeft
Example, the guy selects the day 01/05, on my second datepicker, it will only return, FRIDAYS from the day 01/05, ie the minDate of the second datepicker, has to be the date selected from the first datepicker.
– Michel Henriq
I’ve already done it here:
$("#data-inicio").datepicker({
 beforeShowDay: function(date){ return [date.getDay() == 1, ""] },
 minDate: current,
 onClose: function(dateText, inst) {
 $("#data-retorno").val(dateText);
 }
 });
 $("#data-retorno").datepicker({
 beforeShowDay: function(date){ return [date.getDay() == 5, ""] }, 
 });
});
But in this script, it plays right in 2 datepicker the value selected in the first, but in my case, I wanted it to set the second’s minDate with the date selected from the first.– Michel Henriq
Have you looked at the example I provided in jsfiddle? I just updated: https://jsfiddle.net/ddw8ya41/2/
– Rafael Withoeft
I tidied up your code, now it’s returning from that selected day, and how do I now add up to 7 more days? I edited my question, the current code is updated.
– Michel Henriq
Add to minDate, inside onSelect function, selectedDate + 7:
$("#data-retorno").datepicker("option", "minDate", selectedDate + 7);
apparently it worked right here.– Rafael Withoeft
returned to me July 2070.
– Michel Henriq
KKKK, it’s true, I saw it now. I’ll check
– Rafael Withoeft
@Michelhenriq believes that now it is right, only you modify the rest as you need: https://jsfiddle.net/ddw8ya41/3/
– Rafael Withoeft
There is only one however, in my code, the getDate of the first datapicker is set for next month, and in this case, you are giving this current getDate, IE, when I open the calendar, is appearing to me the month of May, but when I click, it stores the month of April. You could use the same month you’re selected?
– Michel Henriq
Let’s go continue this discussion in chat.
– Rafael Withoeft