This repository was archived by the owner on May 21, 2025. It is now read-only.
Avoid unexcepted errors on "angucomplete" inputs#457
Open
RomainOliva wants to merge 1 commit into
Open
Conversation
I try to solve two problems in this PR.
Use case for the first problem:
- I enter a value for my input then I leave it
- I return in the input
- If I delete a character or modify the current value, an unexcepted required error message appears
- It disappears at the exit of the input.
Here is the solution:
- When writing in the input, for each key up, we enter in the condition `line 291`.
- The problem is for any user input the code call `callOrAssign()` method without parameters.
- When calling `callOrAssign()` input without parameters, the handleRequired(true) method is called and the field becomes invalid.
- What I add is a check, if the value of the input is empty we call `callOrAssign()` method without parameters to have an error, otherwise we send the value entered by the user to the `callOfAssign` method.
In this way, the error no longer appears while the user writes (if the input is not empty).
-------------------
Use case of the second problems:
- I enter a value for my input then I leave it
- I return in the input
- If I completely empty the input an error will appear telling me that the field is mandatory (this is normal)
- But if I rewrite something without leaving the input, the error just stay
Here is the solution:
- When writing to the input, for each key up, we fill the last value of the input in the variable `validState, the problem is that when we empty the input, the `validState` variable is `""` and it never updated.
- So I modified the condition, to check if the `validState` is `undefined` and not if the variable is empty.
In this way, if we empty the input, an error appears, but if we rewrite something, now the error disappears.
Here is the configuration of my angucomplete field:
```
this.brandOptions = {
maxlength: '50',
pause: '100',
selectedObject: this.brandCallbackFunction.bind(this),
localData: this.brands,
searchFields: 'brand',
titleField: 'brand',
minlength: '1',
textNoResults: false,
textSearching: false,
fieldRequired: true,
fieldRequiredClass: 'brand',
initialValue: this.newVariant.brand,
inputName: 'brand',
overrideSuggestions: true
};
```
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I try to solve two problems in this PR.
1. Use case for the first problem:
Here is the solution:
line 291.callOrAssign()method without parameters.callOrAssign()input without parameters, the handleRequired(true) method is called and the field becomes invalid.callOrAssign()method without parameters to have an error, otherwise we send the value entered by the user to thecallOfAssignmethod.In this way, the error no longer appears while the user writes (if the input is not empty).
2. Use case of the second problems:
Here is the solution:
validState, the problem is that when we empty the input, thevalidStatevariable is""` and it never updated.validStateisundefinedand not if the variable is empty.In this way, if we empty the input, an error appears, but if we rewrite something, now the error disappears.
Here is the configuration of my angucomplete field: