feat(web/input): returnString for date inputs (#411)

* feat(interface/input): useFormat field

* feat(interface/input): useFormat field

* feat(types/dialog): useFormat field

* feat(components/date): format date conversion

* tweak(components/date): forgot other data type

* chore(interface/input): more descriptive name

* chore(interface/input): more descriptive name

* chore(types/dialog): more descriptive name

* tweak(components/date): reset things

* feat(dialog/input): date conversion with returnString

* refactor(web/input): remove unnecessary state

---------

Co-authored-by: Luke <39926192+LukeWasTakenn@users.noreply.github.com>
This commit is contained in:
BerkieBb
2023-09-11 21:17:35 +00:00
committed by GitHub
parent 22c77a1ac0
commit 3c0136afd8
5 changed files with 15 additions and 5 deletions

View File

@@ -14,7 +14,8 @@ import ColorField from './components/fields/color';
import DateField from './components/fields/date';
import TextareaField from './components/fields/textarea';
import TimeField from './components/fields/time';
import type { InputProps } from '../../typings';
import type { IDateInput, InputProps } from '../../typings';
import dayjs from 'dayjs';
export type FormValues = {
test: {
@@ -80,6 +81,14 @@ const InputDialog: React.FC = () => {
const onSubmit = form.handleSubmit(async (data) => {
setVisible(false);
const values: any[] = [];
for (let i = 0; i < fields.rows.length; i++) {
const row = fields.rows[i];
if ((row.type === 'date' || row.type === 'date-range') && row.returnString) {
if (!data.test[i]) continue;
data.test[i].value = dayjs(data.test[i].value).format(row.format || 'DD/MM/YYYY');
}
}
Object.values(data.test).forEach((obj: { value: any }) => values.push(obj.value));
await new Promise((resolve) => setTimeout(resolve, 200));
form.reset();