Skip to content

Commit

Permalink
fix: change useForm mode to trigger validation on multiple ways [EP-3…
Browse files Browse the repository at this point in the history
…675]
  • Loading branch information
dan-qc committed Jan 13, 2021
1 parent 6a8a3de commit 5048ffe
Show file tree
Hide file tree
Showing 18 changed files with 18 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default function UserEdit(props: UserEditProps) {
const { name, email, groups, id } = data || {};

const { handleSubmit, register, errors, control, getValues, formState } = useForm({
mode: 'onChange',
mode: 'all',
});
const [serverErrors, setServerErrors] = useState(null);
const [selectedGroups, setSelectedGroups] = useState([]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export function DashboardDetail(props: IProps) {
}, [data]);

const { getValues, register, formState, errors, control } = useForm({
mode: 'onChange',
mode: 'all',
});

const { touched, isDirty, isValid } = formState;
Expand Down
2 changes: 1 addition & 1 deletion packages/earth-admin/src/pages-client/dashboards/new.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export function NewDashboard(props: IProps) {
const { selectedGroup } = useAuth0();
const { t } = useTranslation('admin');
const { register, watch, formState, errors, setValue, control, handleSubmit } = useForm({
mode: 'onChange',
mode: 'all',
});

const { touched, isDirty, isValid } = formState;
Expand Down
2 changes: 1 addition & 1 deletion packages/earth-admin/src/pages-client/layers/details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export function LayerDetail(props: any) {
}, [layer]);

const { getValues, register, formState, errors, control } = useForm({
mode: 'onChange',
mode: 'all',
});

const { touched, isDirty, isValid } = formState;
Expand Down
2 changes: 1 addition & 1 deletion packages/earth-admin/src/pages-client/layers/new.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export function NewLayer(props: IProps) {
const { selectedGroup } = useAuth0();
const { t } = useTranslation('admin');
const { register, watch, formState, errors, setValue, control, handleSubmit } = useForm({
mode: 'onChange',
mode: 'all',
});
const {
category: layerCategoryOptions = [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export function OrganizationDetails(props: OrganizationDetailsProps) {
watch,
reset,
} = useForm({
mode: 'onChange',
mode: 'all',
});

const { touched } = formState;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export function NewOrganization(props: IProps) {
const [ownersFeedback, setOwnersFeedback] = useState([]);
const { selectedGroup, updateToken } = useContext(Auth0Context);
const { handleSubmit, register, errors, formState, setValue, control, watch } = useForm({
mode: 'onChange',
mode: 'all',
});
const { isValid, touched } = formState;
const renderErrorFor = setupErrors(errors, touched);
Expand Down
2 changes: 1 addition & 1 deletion packages/earth-admin/src/pages-client/places/details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export function PlaceDetail(props: IProps) {
} = place;

const { getValues, register, formState, errors } = useForm({
mode: 'onChange',
mode: 'all',
});

const { touched, isDirty, isValid } = formState;
Expand Down
3 changes: 1 addition & 2 deletions packages/earth-admin/src/pages-client/places/new.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,9 @@ export function NewPlace(props: IProps) {
const { onDataChange = noop, dynamicOptions } = props;
const { type: placeTypeOptions = [] } = dynamicOptions;
const { register, handleSubmit, watch, formState, errors, setValue, reset, control } = useForm({
mode: 'onChange',
mode: 'all',
});
const { touched, isDirty, isValid } = formState;
console.log('@@@@@@', isDirty, isValid);
const watchName = watch('name');
const [isLoading, setIsLoading] = useState(false);
const [geojsonValue, setGeojson] = useState(null);
Expand Down
2 changes: 1 addition & 1 deletion packages/earth-admin/src/pages-client/users/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export function UsersHome(props: any) {
);

const { watch, setValue, control, getValues } = useForm({
mode: 'onChange',
mode: 'all',
});

const inviteUsersWatcher = watch('users');
Expand Down
2 changes: 1 addition & 1 deletion packages/earth-admin/src/pages-client/widgets/details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export function WidgetsDetail(props: WidgetProps) {
}, [widget]);

const { getValues, register, formState, errors, control } = useForm({
mode: 'onChange',
mode: 'all',
});

const { touched, isDirty, isValid } = formState;
Expand Down
2 changes: 1 addition & 1 deletion packages/earth-admin/src/pages-client/widgets/new.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export function NewWidget(props: IProps) {
const { selectedGroup } = useAuth0();
const { t } = useTranslation('admin');
const { register, watch, formState, errors, setValue, control, handleSubmit } = useForm({
mode: 'onChange',
mode: 'all',
});

const { touched, isDirty, isValid } = formState;
Expand Down
2 changes: 1 addition & 1 deletion packages/earth-map/src/components/clip-layer/ClipLayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export function ClipLayer(props: IProps) {
const [childLayers, setChildLayers] = useState([]);
const { t } = useTranslation();
const { register, handleSubmit, formState, control, watch, setValue } = useForm({
mode: 'onChange',
mode: 'all',
});
const { isDirty, isValid, isSubmitting } = formState;
const selectedPrimaryLayer = watch('primaryLayer');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export function CollectionDownloadMetrics(props: IProps) {
const [metricSlugs, setMetricSlugs] = useState([]);
const [isLoadingMetricSlugs, setIsLoadingMetricSlugs] = useState(false);
const { register, handleSubmit, formState, control, watch } = useForm({
mode: 'onChange',
mode: 'all',
});
const { isDirty, isValid, isSubmitting } = formState;
const metricsWatcher = watch('metrics');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export function CollectionEditPlaces(props: IProps) {
const [saveError, setSaveError] = useState('');
const [isSaveConflict, setIsSaveConflict] = useState(false);
const { control, handleSubmit, formState, getValues } = useForm({
mode: 'onChange',
mode: 'all',
});
const { isValid, isSubmitting, isDirty } = formState;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const CollectionNew = (props: IProps) => {
const { t } = useTranslation();
const canCreateCollection = !!privateGroups.length;
const [saveError, setSaveError] = useState(null);
const { handleSubmit, register, errors, formState } = useForm({ mode: 'onChange' });
const { handleSubmit, register, errors, formState } = useForm({ mode: 'all' });
const { touched, isDirty, isValid, isSubmitting } = formState;
const renderErrorFor = setupErrors(errors, touched);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function CollectionRename(props: IProps) {
const [saveError, setSaveError] = useState('');
const [isSaveConflict, setIsSaveConflict] = useState(false);
const { register, errors, handleSubmit, formState, getValues } = useForm({
mode: 'onChange',
mode: 'all',
});
const { touched, isDirty, isValid, isSubmitting } = formState;
const renderErrorFor = setupErrors(errors, touched);
Expand Down
2 changes: 1 addition & 1 deletion packages/earth-map/src/pages/profile/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export function ProfileComponent(props: IProps) {
const { t } = useTranslation();

const { getValues, register, formState, errors: formErrors } = useForm({
mode: 'onChange',
mode: 'all',
});

const { userData, logout, login, isAuthenticated, updateToken } = useContext(Auth0Context);
Expand Down

0 comments on commit 5048ffe

Please sign in to comment.