GithubHelp home page GithubHelp logo

Comments (14)

third774 avatar third774 commented on July 19, 2024

Are you using an async validator?

from ng-bootstrap-form-validation.

ONbik-srebollo avatar ONbik-srebollo commented on July 19, 2024

Yes, obviously. If I remove this validator, all works. But this validation breaks form validation.

from ng-bootstrap-form-validation.

kingcody avatar kingcody commented on July 19, 2024

@ONbik-srebollo could you post a link to a code base or plunkr that reproduces your issue?

from ng-bootstrap-form-validation.

ONbik-srebollo avatar ONbik-srebollo commented on July 19, 2024

This is the field definition on FormGroup (with another fields):

    this.formGroup = this.formBuilder.group({
      'tin': [null, Validators.compose([Validators.required, tinValidator()]), this.asyncTinValidator.bind(this)],
    });

And this my asyn validator.

  asyncTinValidator(tinCtrl: FormControl): { [key: string]: any } {
    return new Promise (resolve => {
      return this.companyManager.checkTin(tinCtrl.value)
        .then(result => {
          return null;
        }).catch(error => {
          return { 'tin': { value: tinCtrl.value, message: error.error } };
        });
    });
  }

tinValidator is a sync function that only validates format. This works perfectly, and this fails even if I remove all sync validators.

I would like to get a working example with this vendor, because I think this works (I've copied an example from official doc of Angular) but perhaps there is something wrong.

Thanks in advance for your patience.

from ng-bootstrap-form-validation.

kingcody avatar kingcody commented on July 19, 2024

@ONbik-srebollo @third774 we need to filter out any control.errors that are null instead of ValidationErrors:

src/lib/Components/form-group-component/form-group-component.ts#87

- this.FormControlNames.filter(c => !c.valid)
+ this.FormControlNames.filter(c => !c.valid && !!c.errors)

This is the outcome with a 2 second async validation timeout:

async-validation

from ng-bootstrap-form-validation.

third774 avatar third774 commented on July 19, 2024

What do y'all think of adding .has-warning to the form group if an async validation is pending?

from ng-bootstrap-form-validation.

ONbik-srebollo avatar ONbik-srebollo commented on July 19, 2024

Hi @third774 .

I think it's not necessary, the validation is fast and it would be confusing to the user.

Thank you @kingcody !!!

from ng-bootstrap-form-validation.

kingcody avatar kingcody commented on July 19, 2024

I haven't done a lot of research, but do you know how we would determine if a field is pending an async validation?

from ng-bootstrap-form-validation.

third774 avatar third774 commented on July 19, 2024

Checking the status property should do it.

https://angular.io/api/forms/AbstractControl

from ng-bootstrap-form-validation.

ONbik-srebollo avatar ONbik-srebollo commented on July 19, 2024

Be careful...

Now valid property is validated, that is the same as validate status !== valid. The PENDING status would be considered as error like now. I think is better @kingcody option to check if control has errors.

from ng-bootstrap-form-validation.

third774 avatar third774 commented on July 19, 2024

We're going to address the pending status in a separate issue.

from ng-bootstrap-form-validation.

ONbik-srebollo avatar ONbik-srebollo commented on July 19, 2024

Hi @third774 and @kingcody

I see that this will be fixed by #26 but it seems to be available on v3.

It's possible to be available on v2.2 ? I need it.

I'm trying to use it adding it to package.json:

"ng-bootstrap-form-validation": "^2.1.0-dev.20180130230430257Z.878bd2d1a9ab7c12256a15e87a9fb32458fd56b1",

But it isn't there. And I can't use dev-master, i don't know why (sorry, i'm a bit newbie).

Can you help me, please?

Thanks in advance.

from ng-bootstrap-form-validation.

kingcody avatar kingcody commented on July 19, 2024

@ONbik-srebollo try this:

npm install --save ng-bootstrap-form-validation@2.1.0-dev.20180130230430257Z.878bd2d1a9ab7c12256a15e87a9fb32458fd56b1

or

yarn add ng-bootstrap-form-validation@2.1.0-dev.20180130230430257Z.878bd2d1a9ab7c12256a15e87a9fb32458fd56b1

from ng-bootstrap-form-validation.

ONbik-srebollo avatar ONbik-srebollo commented on July 19, 2024

Thank you so much!!!!

I don't know what happened, but now has installed correctly. Async validation know works perfectly!!!

from ng-bootstrap-form-validation.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.