create form using states instead of formik

formik (or any other form framework) doesn't support setting field value programmatically. filter form uses 2 fields that are triggered by clicking a button, and that's the reason there's no other workaround. probably needs a rewrite
This commit is contained in:
b1ek 2023-05-08 20:32:50 +10:00
parent ff321143aa
commit b5828134a9
Signed by: blek
GPG Key ID: 14546221E3595D0C
1 changed files with 31 additions and 35 deletions

View File

@ -2,7 +2,6 @@ import React, { useState } from "react";
import { Swiper, SwiperSlide } from 'swiper/react'; import { Swiper, SwiperSlide } from 'swiper/react';
import { Scrollbar, Navigation } from 'swiper/core'; import { Scrollbar, Navigation } from 'swiper/core';
import ISVGIcon from '../../components/UI/Icon/SVGIcon'; import ISVGIcon from '../../components/UI/Icon/SVGIcon';
import { Formik, Field, Form } from 'formik';
import styled from 'styled-components'; import styled from 'styled-components';
import 'swiper/css'; import 'swiper/css';
@ -113,47 +112,44 @@ const FiltersForm = () => {
per_month: false per_month: false
}; };
const [ state, setState ] = useState(def_form);
const submitted = (a) => { const submitted = (a) => {
console.log(a); console.log(a);
} }
return ( return (
<Formik <Filters>
initialValues={def_form} <FilterText>Фильтры</FilterText>
onSubmit={async (values) => {
console.log(values);
}}
>
<Form>
<Filters>
<FilterText>Фильтры</FilterText>
<PeriodFilter> <PeriodFilter>
<PeriodButton> <PeriodButton
<SVGIcon src='/images/icons/calendar-day.svg' width='14' height='14' /> active={state.per_day}
Посуточно onClick={() => setState({per_day: !state.per_day})}>
</PeriodButton> <SVGIcon src='/images/icons/calendar-day.svg' width='14' height='14' />
<PeriodButton> Посуточно
<SVGIcon src='/images/icons/calendar.svg' width='14' height='14' /> </PeriodButton>
Ежемесячно <PeriodButton
</PeriodButton> active={state.per_month}
<ClearButton> onClick={() => setState({per_month: !state.per_month})}>
<SVGIcon src='/images/icons/eraser-fill.svg' width='14' height='14' /> <SVGIcon src='/images/icons/calendar.svg' width='14' height='14' />
Сбросить Ежемесячно
</ClearButton> </PeriodButton>
</PeriodFilter> <ClearButton>
<SVGIcon src='/images/icons/eraser-fill.svg' width='14' height='14' />
Сбросить
</ClearButton>
</PeriodFilter>
<SearchBarFilter> <SearchBarFilter>
asbvccxcz asbvccxcz
</SearchBarFilter> </SearchBarFilter>
<SubmitBtn type='submit'> <SubmitBtn type='submit'>
<SVGIcon src='/images/icons/search.svg' width='14' height='14' /> <SVGIcon src='/images/icons/search.svg' width='14' height='14' />
Показать варианты Показать варианты
</SubmitBtn> </SubmitBtn>
</Filters> </Filters>
</Form>
</Formik>
); );
} }