Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

281
Views
Deshabilitar fines de semana y fechas específicas jQueryUI datepicker

Quiero deshabilitar los fines de semana en el selector de fechas, así como las fechas específicas que estarán en una matriz. He notado que no puedo combinar estas 2 opciones en beforeShowDay ya que solo acepta 1 función. ¿Hay alguna manera de agregar 2 funciones en beforeShowDay ?

 $(function() { var unavailableDates = ["27-12-2021", "28-12-2021", "29-12-2021", "30-12-2021", "31-12-2021", "01-01-2022", "02-01-2022", "03-01-2022", "04-01-2022"]; function unavailable(date) { dmy = date.getDate() + "-" + (date.getMonth() + 1) + "-" + date.getFullYear(); if ($.inArray(dmy, unavailableDates) == -1) { return [true, ""]; } else { return [false, "", "Unavailable"]; } } $("#datepicker").datepicker({ dateFormat: "dd-mm-yy", changeMonth: false, changeYear: false, minDate: '10D', beforeShowDay: $.datepicker.noWeekends, unavailable // throws an error becaus ei have 2 options }); });
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script> <script src="https://code.jquery.com/ui/1.13.0/jquery-ui.min.js"></script> <link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css" /> <input type="text" id="datepicker" />

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

El problema se debe a que la propiedad beforeShowDay solo acepta una sola función.

Para hacer lo que necesita, puede crear una función anónima en la que llame a las funciones noWeekends() y unavailable() y combine el resultado, así:

 jQuery($ => { let unavailableDates = ["27-12-2021", "28-12-2021", "29-12-2021", "30-12-2021", "31-12-2021", "01-01-2022", "02-01-2022", "03-01-2022", "04-01-2022"]; let isUnavailable = date => $.inArray(`${date.getDate()}-${(date.getMonth() + 1)}-${date.getFullYear()}`, unavailableDates) >= 0; $("#datepicker").datepicker({ dateFormat: "dd-mm-yy", changeMonth: false, changeYear: false, minDate: '10D', beforeShowDay: date => { if (isUnavailable(date) || !$.datepicker.noWeekends(date)[0]) { return [false, "", "Unavailable"]; } else { return [true, ""]; } } }); });
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script> <script src="https://code.jquery.com/ui/1.13.0/jquery-ui.min.js"></script> <link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css" /> <input type="text" id="datepicker" />

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!