Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ import { withRuleEngine } from '../utils/withRuleEngine';
import { PROPS } from '../utils/type';
import FieldWrapper from './common/FieldWrapper';
import { syncAriaDescribedBy } from '../utils/utils';
import { formatDate } from '@aemforms/af-formatters';

const DateInput = (props: PROPS) => {
const { id, label, value, required, name, readOnly, placeholder, visible, enabled, appliedCssClassNames, valid } = props;
const { id, label, value, required, name, readOnly, placeholder, visible, enabled, appliedCssClassNames, valid, editFormat } = props;
const finalValue = value === undefined ? '' : value;

const changeHandler = useCallback((e: React.ChangeEvent<HTMLInputElement>) => {
Expand All @@ -40,6 +41,10 @@ const DateInput = (props: PROPS) => {
props.dispatchBlur();
}, [props.dispatchBlur]);

const locale = new Intl.DateTimeFormat().resolvedOptions().locale;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to access locale from the current context, its part of the model

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We expose lang in field state, could you try using that instead ?


const defaultDescription = `To enter today's date use ${formatDate(new Date(), locale, editFormat)}`;

return (
<div
className={`cmp-adaptiveform-datepicker cmp-adaptiveform-datepicker--${value ? 'filled' : 'empty'} ${appliedCssClassNames || ''}`}
Expand All @@ -54,7 +59,7 @@ const DateInput = (props: PROPS) => {
label={label}
id={id}
tooltip={props.tooltip}
description={props.description}
description= {props.description ? props.description : defaultDescription}
isError={props.isError}
errorMessage={props.errorMessage}
>
Expand Down