-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
OptionsSelector display max length error with counter when exceeded #28722
Changes from 7 commits
05095d0
64d8a3d
40354e1
7728993
fde11f9
afc7d69
9b98e98
731219c
51e0e9c
0c00e23
b57df36
d5e39c2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,6 +54,7 @@ class BaseOptionsSelector extends Component { | |
this.selectRow = this.selectRow.bind(this); | ||
this.selectFocusedOption = this.selectFocusedOption.bind(this); | ||
this.addToSelection = this.addToSelection.bind(this); | ||
this.updateSearchValue = this.updateSearchValue.bind(this); | ||
this.relatedTarget = null; | ||
|
||
const allOptions = this.flattenSections(); | ||
|
@@ -63,6 +64,7 @@ class BaseOptionsSelector extends Component { | |
allOptions, | ||
focusedIndex, | ||
shouldDisableRowSelection: false, | ||
errorMessage: '', | ||
}; | ||
} | ||
|
||
|
@@ -166,6 +168,14 @@ class BaseOptionsSelector extends Component { | |
return defaultIndex; | ||
} | ||
|
||
updateSearchValue(value) { | ||
this.setState({ | ||
errorMessage: value.length > this.props.maxLength ? this.props.translate('common.error.characterLimitExceedCounter', {length: value.length, limit: this.props.maxLength}) : '', | ||
}); | ||
|
||
this.props.onChangeText(value); | ||
} | ||
|
||
subscribeToKeyboardShortcut() { | ||
const enterConfig = CONST.KEYBOARD_SHORTCUTS.ENTER; | ||
this.unsubscribeEnter = KeyboardShortcut.subscribe( | ||
|
@@ -365,10 +375,11 @@ class BaseOptionsSelector extends Component { | |
label={this.props.textInputLabel} | ||
accessibilityLabel={this.props.textInputLabel} | ||
accessibilityRole={CONST.ACCESSIBILITY_ROLE.TEXT} | ||
onChangeText={this.props.onChangeText} | ||
onChangeText={this.updateSearchValue} | ||
errorText={this.state.errorMessage} | ||
onSubmitEditing={this.selectFocusedOption} | ||
placeholder={this.props.placeholderText} | ||
maxLength={this.props.maxLength} | ||
maxLength={this.props.maxLength + CONST.ERROR_EXCEED_RANGE} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am confused, can you explain this change? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @flodnv ![]() There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Sorry I am not seeing what that means on your screenshot 😕 What do you mean by "will show the error from 501 to 520"? What and where will the "501 to 520" error show? 😕 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @flodnv // the length can user type it without see the error with counter in the scrrenshot above.
this.props.maxLength = 500;
// the range we will display the error from 501 to 520
CONST.ERROR_EXCEED_RANGE = 20;
// so the max length that user can type at all and the input will allow it will be
maxLength={this.props.maxLength + CONST.ERROR_EXCEED_RANGE} 501 to 520 mean when the typed text length is between 501 and 520 characters, the error with counter will be displayed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So if I understand this correctly, it is impossible to type past 520 chars? What if I paste 1000 chars there? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we paste 1000 char, it will paste only 520 char, because the input maxLength don't let it accept more than 520 char, and this is the default behavior for maxLength, you can try here |
||
keyboardType={this.props.keyboardType} | ||
onBlur={(e) => { | ||
if (!this.props.shouldFocusOnSelectRow) { | ||
|
@@ -394,7 +405,7 @@ class BaseOptionsSelector extends Component { | |
multipleOptionSelectorButtonText={this.props.multipleOptionSelectorButtonText} | ||
onAddToSelection={this.addToSelection} | ||
hideSectionHeaders={this.props.hideSectionHeaders} | ||
headerMessage={this.props.headerMessage} | ||
headerMessage={this.state.errorMessage ? '' : this.props.headerMessage} | ||
boldStyle={this.props.boldStyle} | ||
showTitleTooltip={this.props.showTitleTooltip} | ||
isDisabled={this.props.isDisabled} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Now that I understand what this is, I can suggest what I think is a better name along with some nice docs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the comment makes it more understandable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about renaming the variable itself?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, correct, I missed that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@flodnv updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!