Skip to content

Commit

Permalink
Merge pull request #8512 from eVoloshchak/eVoloshchak_auditForms
Browse files Browse the repository at this point in the history
Fix: Do not modify room name on the UI in RoomNameInput.
  • Loading branch information
deetergp authored Apr 12, 2022
2 parents fd0f83a + db7f343 commit 8419bd4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 16 deletions.
18 changes: 3 additions & 15 deletions src/components/RoomNameInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,29 +56,17 @@ const defaultProps = {
class RoomNameInput extends Component {
constructor(props) {
super(props);
this.state = {
roomName: props.initialValue,
};

this.setModifiedRoomName = this.setModifiedRoomName.bind(this);
}

/**
* Sets the modified room name in the state and calls the onChangeText callback
* Calls the onChangeText callback with a modified room name
* @param {Event} event
*/
setModifiedRoomName(event) {
const nativeEvent = event.nativeEvent;
const roomName = nativeEvent.text;
const target = nativeEvent.target;
const selection = target.selectionStart;
const roomName = event.nativeEvent.text;
const modifiedRoomName = this.modifyRoomName(roomName);
this.setState({roomName: modifiedRoomName}, () => {
if (!selection) {
return;
}
target.selectionEnd = selection;
});
this.props.onChangeText(modifiedRoomName);
}

Expand Down Expand Up @@ -108,7 +96,7 @@ class RoomNameInput extends Component {
prefixCharacter={CONST.POLICY.ROOM_PREFIX}
placeholder={this.props.translate('newRoomPage.social')}
onChange={this.setModifiedRoomName}
value={this.state.roomName.substring(1)}
defaultValue={this.props.initialValue.substring(1)} // Since the room name always starts with a prefix, we omit the first character to avoid displaying it twice.
errorText={this.props.errorText}
autoCapitalize="none"
/>
Expand Down
1 change: 0 additions & 1 deletion src/pages/workspace/WorkspaceNewRoomPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ class WorkspaceNewRoomPage extends React.Component {
<ScrollView style={styles.flex1} contentContainerStyle={styles.p5}>
<View style={styles.mb5}>
<RoomNameInput
initialValue={this.state.roomName}
policyID={this.state.policyID}
errorText={this.state.errors.roomName}
onChangeText={roomName => this.clearErrorAndSetValue('roomName', roomName)}
Expand Down

0 comments on commit 8419bd4

Please sign in to comment.