Skip to content
Merged
Show file tree
Hide file tree
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
11 changes: 9 additions & 2 deletions demo/FormExamples.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ export function FormExamples() {
checkboxField2: true,
radioField2: 'b',
numberField: null,
dateField: new Date().toISOString(),
dateTimeField: new Date().toISOString(),
dateField2: new Date().toISOString(),
dropdownField1: {
title: 'Title two',
},
Expand Down Expand Up @@ -212,7 +213,13 @@ export function FormExamples() {
/>
</div>
<div className="col">
<FormGroupInput name="dateField" label="Date field" type="datetime-local" />
<FormGroupInput name="dateTimeField" label="Datetime field" type="datetime-local" />
</div>
<div className="col">
<FormGroupInput name="dateField1" label="Date field" type="date" />
</div>
<div className="col">
<FormGroupInput name="dateField2" label="Date field with ISO date initialValue" type="date" />
</div>
</div>

Expand Down
9 changes: 8 additions & 1 deletion demo/UncontrolledFormExamples.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export function UncontrolledFormExamples() {
textarea1:
'Lorem ipsum dolor sit amet consectetur adipisicing elit. Atque praesentium quisquam reiciendis expedita. Ad quod voluptas aliquid illum veniam odio? Nulla sed, illum eligendi amet fuga optio officia itaque nisi',
dateMask: '0410202',
inputDate2: new Date().toISOString(),
}}
onSubmit={(data) => console.log('onSubmit', data)}
onChange={(data) => console.log('onChange', data)}
Expand Down Expand Up @@ -117,7 +118,13 @@ export function UncontrolledFormExamples() {
<FormArrayOfObjects />
</div>
<div className="mb-3">
<UncontrolledFormGroupInput label="Input date" name="inputDate" type="datetime-local" />
<UncontrolledFormGroupInput label="Input date time" name="inputDateTime" type="datetime-local" />
</div>
<div className="mb-3">
<UncontrolledFormGroupInput label="Input date" name="inputDate1" type="date" />
</div>
<div className="mb-3">
<UncontrolledFormGroupInput label="Input date with ISO date initialValue" name="inputDate2" type="date" />
</div>
<UncontrolledFormGroupAutocomplete
name="autocomplete2Field1"
Expand Down
7 changes: 7 additions & 0 deletions src/forms/FormInput.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React, { useCallback } from 'react';
import PropTypes from 'prop-types';

import { isDateISOString } from 'js-var-type';

import { formatClasses } from '../utils/attributes';

import { useFormControl } from './helpers/useFormControl';
Expand Down Expand Up @@ -31,6 +33,11 @@ export function FormInput({

if (type === 'datetime-local') {
attrs.defaultValue = getValue();
} else if (type === 'date') {
const value = getValue();

//match em tudo antes do T da data ISO
attrs.value = isDateISOString(value) ? value.split('T')[0] : value;
} else {
attrs.value = getValue();
}
Expand Down
7 changes: 7 additions & 0 deletions src/uncontrolled-forms/UncontrolledFormInput.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React, { useState } from 'react';
import PropTypes from 'prop-types';

import { isDateISOString } from 'js-var-type';

import { formatClasses } from '../utils/attributes';

import { booleanOrFunction } from './helpers/form-helpers';
Expand Down Expand Up @@ -36,6 +38,11 @@ export function UncontrolledFormInput({

if (type === 'datetime-local') {
attrs.defaultValue = getValue() ?? '';
} else if (type === 'date') {
const value = getValue() ?? '';

//match em tudo antes do T da data ISO
attrs.value = isDateISOString(value) ? value.split('T')[0] : value;
} else {
attrs.value = getValue() ?? '';
}
Expand Down