score:5
Accepted answer
To start we have a look at antd's Datepicker example in the depending docs.
- Disable all Sundays
We use the moment.js lib to check the days and disable all sundays (here it is the first == zero).
E.g.:
function disabledDate(current) {
// Can not select sundays and predfined days
return moment(current).day() === 0
}
- Disable specific days
First we define an array of our dates and then check if a converted day is in our disabled array.
const disabledDates = ["2020-07-21", "2020-07-23"];
function disabledDate(current) {
// Can not select Sundays and predefined days
return disabledDates.find(date => date === moment(current).format("YYYY-MM-DD"));
}
- Putting all together
Now we can combine both solutions. A working example can be found in this CodeSandbox.
E.g.:
import React from "react";
import ReactDOM from "react-dom";
import "antd/dist/antd.css";
import "./index.css";
import moment from "moment";
import { DatePicker } from "antd";
const disabledDates = ["2020-07-21", "2020-07-23"];
function disabledDate(current) {
// Can not select Sundays and predefined days
return (
moment(current).day() === 0 ||
disabledDates.find(date => date === moment(current).format("YYYY-MM-DD"))
);
}
ReactDOM.render(
<>
<DatePicker
format="YYYY-MM-DD HH:mm:ss"
disabledDate={disabledDate}
showTime={{ defaultValue: moment("00:00:00", "HH:mm:ss") }}
/>
</>,
document.getElementById("container")
);
score:0
If you don't want to use the "Moment" library, you can do as I did:
const disabledDate = (current) => {
return (
current < Date.now() ||
(new Date(current).getDay() === 0 ||
new Date(current).getDay() === 6)
);
};
Source: stackoverflow.com
Related Query
- how to disable all the Sundays and array of specific days in ant design date picker
- How do I get my HTML form date input to only allow specific days of the week to be chosen using JavaScript, React and HTML?
- How to add the input field inside the select option using ant design and react
- How to display the date month and year in a specific format using javascript and react?
- DatePicker ant design - disable the current/todays date
- How to group arrays of objects by value and add the result to another array with same value at specific key
- How can I get all the object inside an object which is present inside an array and add the result into another array
- Removing specific item from nested array and saving the result, how to make this code cleaner
- How to print json object array to print all the values as category and subcategory
- How do I take an array of objects from state and push a specific value of the objects into a new array
- How can I group specific items within an object in the same array and delete them from the core array?
- How to update React properties after a delay in time and constantly sort an array to the nearest specific number X?
- How to do a foreach for an array with values that have to match specific key and the same value from another array
- How to find all of the style attributes I can edit in ant design component?
- How can I set a specific position to array elements with the map function and a given index?
- How to make ajax request to the firestore, receive an array and make new request for all items of the array in redux-saga?
- I want to accept only 1-24 in the input field and disable all other buttons. how is it possible
- How can I pass an array of values in the Ant Design cascader?
- How to get all of the past 30 days records in JSON array based their DD/MM/YYYY field?
- How to convert moment date to a string and remove the moment object
- How to fetch data only once in a Next.js app and make it accesible to all the app, both in server and client
- How should customRequest be set in the Ant Design Upload component to work with an XMLHttpRequest?
- How to disable and hide the pagination footer for react-table?
- How can we configure the Header of ant design table component?
- How do I implement minimum 5 characters validation in this ant design login form ? I cant find the examples
- How to push into an array of object using the spread operator to a specific element
- How to disable a field in Ant Design React Form?
- How to test ant design date picker using @testing-library/react?
- How do I tell the custom onSuccess function to stop the upload spinner in Ant Design Upload component?
- How to use Google reCAPTCHA in the Ant Design Form component?
More Query from same tag
- Retrieving custom claims Firebase/React immediately after authentication
- Error while configuring CSS modules with webpack
- Redirect doesn't work after onClick in React
- Updating progress bar state on browser scroll
- How to mask password with MaterialTable
- React API Reference
- How to create onSubmit with Material-UI
- Warning: Received `false` for a non-boolean attribute. How do I pass a boolean value?
- Global variable not defined across multiple useEffects
- Nodemailer multiple recipients
- Why is my React function not waiting for the SweetAlert confirmation?
- React and Axios : Axios Can't Access Java/SpringBoot REST Backend Service Because of CORS Policy
- How to toggle and check a Material UI Checkbox in Enzyme / Jest Test
- undefined method `map' for "1,2":String
- Add a dynamic email in between localized translations
- problems with react and "this" even after binding
- REACT: Cannot read property 'map' of undefined in select in form
- React, variable speed Clock with setTimeout
- Combine a small React app, with a simple html/css/js website
- MVC6 How to remove bower from project
- Using dotenv module with React
- How to store the new updated values with keys from slider Material UI ReactJS
- Unable to set loading indicator with useState hook in React
- How to implement logout functionality when clicked on browser window or tab close in JavaScript?
- Focus on Input when DIV is clicked
- Meteor react logout event
- can I use context API as almost another source of truth in a project that already has Redux?
- React JS: Component Not Exported
- Remove all items from array using Reducer - React
- Material UI Card alignment listing