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

Avoid unexcepted errors on "angucomplete" inputs #457

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Commits on Dec 27, 2016

  1. Avoid unexcepted errors on "angucomplete" inputs

    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
        };
    ```
    RomainOliva committed Dec 27, 2016
    Configuration menu
    Copy the full SHA
    7321b37 View commit details
    Browse the repository at this point in the history