Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix validate text is not translated in PDFPasswordForm #22565

Merged
merged 1 commit into from
Jul 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/components/PDFView/PDFPasswordForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class PDFPasswordForm extends Component {
this.updatePassword = this.updatePassword.bind(this);
this.showForm = this.showForm.bind(this);
this.validateAndNotifyPasswordBlur = this.validateAndNotifyPasswordBlur.bind(this);
this.getErrorText = this.getErrorText.bind(this);
}

componentDidUpdate(prevProps) {
Expand All @@ -66,6 +67,17 @@ class PDFPasswordForm extends Component {
this.textInputRef.focus();
}

getErrorText() {
if (this.props.isPasswordInvalid) {
return this.props.translate('attachmentView.passwordIncorrect');
}
if (!_.isEmpty(this.state.validationErrorText)) {
return this.props.translate(this.state.validationErrorText);
}

return '';
}

submitPassword() {
if (!this.validate()) {
return;
Expand All @@ -86,7 +98,7 @@ class PDFPasswordForm extends Component {
return true;
}
this.setState({
validationErrorText: this.props.translate('attachmentView.passwordRequired'),
validationErrorText: 'attachmentView.passwordRequired',
});
return false;
}
Expand All @@ -101,6 +113,7 @@ class PDFPasswordForm extends Component {
}

render() {
const errorText = this.getErrorText();
const containerStyle = this.props.isSmallScreenWidth ? [styles.flex1, styles.w100] : styles.pdfPasswordForm.wideScreenWidth;

return (
Expand All @@ -127,7 +140,7 @@ class PDFPasswordForm extends Component {
onChangeText={this.updatePassword}
returnKeyType="done"
onSubmitEditing={this.submitPassword}
errorText={this.props.isPasswordInvalid ? this.props.translate('attachmentView.passwordIncorrect') : this.state.validationErrorText}
errorText={errorText}
onFocus={() => this.props.onPasswordFieldFocused(true)}
onBlur={this.validateAndNotifyPasswordBlur}
autoFocus
Expand Down