Skip to content

Commit 080e520

Browse files
committed
form is not getting dirty on switch value update
1 parent 8872b9c commit 080e520

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

app/views/RoomInfoEditView/index.tsx

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { BlockContext } from '@rocket.chat/ui-kit';
33
import { dequal } from 'dequal';
44
import { AccessibilityInfo, Alert, Keyboard, ScrollView, Text, View } from 'react-native';
55
import { useForm } from 'react-hook-form';
6+
import { type SetValueConfig } from 'react-hook-form';
67
import * as yup from 'yup';
78
import { yupResolver } from '@hookform/resolvers/yup';
89

@@ -39,6 +40,11 @@ const MESSAGE_TYPE_VALUES = MessageTypeValues.map(m => ({
3940
text: { text: I18n.t('Hide_type_messages', { type: I18n.t(m.text) }) }
4041
}));
4142

43+
const dirtyOptions: SetValueConfig = {
44+
shouldDirty: true,
45+
shouldValidate: true
46+
};
47+
4248
const schema = yup.object().shape({
4349
name: yup.string().required(I18n.t('Name_required'))
4450
});
@@ -283,29 +289,29 @@ const RoomInfoEditView = ({ navigation, route }: IRoomInfoEditViewProps) => {
283289

284290
const toggleRoomType = (value: boolean) => {
285291
logEvent(events.RI_EDIT_TOGGLE_ROOM_TYPE);
286-
setValue('t', value);
287-
setValue('encrypted', value && encrypted);
292+
setValue('t', value, dirtyOptions);
293+
setValue('encrypted', value && encrypted, dirtyOptions);
288294
};
289295

290296
const toggleReadOnly = (value: boolean) => {
291297
logEvent(events.RI_EDIT_TOGGLE_READ_ONLY);
292-
setValue('readOnly', value);
298+
setValue('readOnly', value, dirtyOptions);
293299
};
294300

295301
const toggleReactions = (value: boolean) => {
296302
logEvent(events.RI_EDIT_TOGGLE_REACTIONS);
297-
setValue('reactWhenReadOnly', value);
303+
setValue('reactWhenReadOnly', value, dirtyOptions);
298304
};
299305

300306
const toggleHideSystemMessages = (value: boolean) => {
301307
logEvent(events.RI_EDIT_TOGGLE_SYSTEM_MSG);
302-
setValue('enableSysMes', value);
303-
setValue('systemMessages', value ? systemMessages : []);
308+
setValue('enableSysMes', value, dirtyOptions);
309+
setValue('systemMessages', value ? systemMessages : [], dirtyOptions);
304310
};
305311

306312
const toggleEncrypted = (value: boolean) => {
307313
logEvent(events.RI_EDIT_TOGGLE_ENCRYPTED);
308-
setValue('encrypted', value);
314+
setValue('encrypted', value, dirtyOptions);
309315
};
310316

311317
const onResetPress = () => {

0 commit comments

Comments
 (0)