Subversion Repositories SmartDukaan

Rev

Rev 36842 | Rev 36845 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 36842 Rev 36843
Line 14... Line 14...
14
    return `${y}-${m}-${day}`;
14
    return `${y}-${m}-${day}`;
15
}
15
}
16
 
16
 
17
// Restrict the Acquired Date picker to the last 7 days (today and the 7 days before it).
17
// Restrict the Acquired Date picker to the last 7 days (today and the 7 days before it).
18
// The form HTML is injected via AJAX, so set min/max lazily when the field is focused.
18
// The form HTML is injected via AJAX, so set min/max lazily when the field is focused.
-
 
19
// NOTE: native min/max only reliably greys out dates in Chrome's calendar; Firefox/Safari
-
 
20
// still let the user pick an out-of-range date, so we also enforce the range on 'change'.
19
$(document).on('focus', 'input[name="acquiredDate"]', function () {
21
$(document).on('focus', 'input[name="acquiredDate"]', function () {
20
    const today = new Date();
22
    const today = new Date();
21
    const minDate = new Date();
23
    const minDate = new Date();
22
    minDate.setDate(today.getDate() - 7);
24
    minDate.setDate(today.getDate() - 7);
23
    $(this).attr('max', toLocalYMD(today));
25
    $(this).attr('max', toLocalYMD(today));
24
    $(this).attr('min', toLocalYMD(minDate));
26
    $(this).attr('min', toLocalYMD(minDate));
25
});
27
});
26
 
28
 
-
 
29
// Browser-independent guard: if the selected Acquired Date is outside the last 7 days,
-
 
30
// reject it immediately (clear the field) instead of waiting until form submit.
-
 
31
$(document).on('change', 'input[name="acquiredDate"]', function () {
-
 
32
    const picked = $(this).val();
-
 
33
    if (!picked) return;
-
 
34
    const acq = new Date(picked);
-
 
35
    const today = new Date();
-
 
36
    today.setHours(0, 0, 0, 0);
-
 
37
    const minAllowed = new Date(today);
-
 
38
    minAllowed.setDate(today.getDate() - 7);
-
 
39
    if (acq > today || acq < minAllowed) {
-
 
40
        alert('Acquired date must be within the last 7 days (today or up to 7 days ago).');
-
 
41
        $(this).val('');
-
 
42
    }
-
 
43
});
-
 
44
 
27
 
45
 
28
$(document).on('change', "#maritalStatus", function () {
46
$(document).on('change', "#maritalStatus", function () {
29
    let maritalStatus = $(this).val();
47
    let maritalStatus = $(this).val();
30
    if (maritalStatus == 1) {
48
    if (maritalStatus == 1) {
31
        $(".loiAnniversaryDate").removeClass('hide-model');
49
        $(".loiAnniversaryDate").removeClass('hide-model');