Estoy trabajando en un requisito para mostrar la fecha actual en el campo de fecha.
En el siguiente ejemplo, si cambio defaultValue a value, veo que currentDate se muestra en la carga de la página para el elemento de fecha. Pero incluso después de seleccionar una fecha diferente, veo que se muestra la fecha actual.
Si mantengo el valor predeterminado, la fecha actual no se muestra. ¿Alguien podría sugerir cómo mostrar la fecha actual en la carga de la página y la fecha se puede cambiar si es necesario a cualquier otra fecha?
< DatepickerInput id = "run-now-date-range-from" label = "Time frame from date" isSrOnlyLabel = { true } name = "runNowOptions.dateRange.dateRangeFrom" defaultValue = { currentDate } validate = { value => { let error = ""; if (!validateDate(value)) { error = controllerData?.reportTemplates[selectedReportTemplateIndex]?.runNowOptions?.dateRange?.showFutureDate ? "Please enter a from date up to 46 days in the future." : "Please enter a from date."; } return error; } } settings = { { endDate: getDateRange(controllerData?.reportTemplates[selectedReportTemplateIndex]), startDate: controllerData?.reportTemplates[selectedReportTemplateIndex]?.runNowOptions?.dateRange?.showFutureDate ? "0d" : "", } } /> import React, { InputHTMLAttributes } from "react"; import { InputProps } from "./utils/input-types"; export declare type DatepickerInputProps = InputHTMLAttributes < HTMLInputElement > & InputProps & { settings ? : any; microcopy ? : string; validate ? : (any: any) => string; }; declare const DatepickerInput: React.FC < DatepickerInputProps > ; export default DatepickerInput;en javaScript hay una función incorporada Fecha ()
Puedes darle una oportunidad
const foo = new Date(); //above statement will return the current date const foo = new Date(2022, 08, 22); //above statement will return the date 22/08/2022 //so you can use variable to set the date value like below const foo = new Date(year, month , day);