mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-18 07:26:02 +01:00
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:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user