Angular Form validator only works when typing in text box











up vote
0
down vote

favorite












I am developing a small app in angular5 with PHP. I have an issue in validating form. Form validator works fine when I input data by typing in keyboard. But it is not working when I fill data with javascript.



For example



In email field,



If I type myemail , Its showing invalid email. works good.
But If I set using javascript like $('#email').value('asdsa@gmail.com') its not working.



Form



Validator



enter image description here



What is wrong? I am new to Angular5.










share|improve this question


















  • 3




    instead of directly manipulating DOM, try setting value of form control manually this.registerForm.controls['email'].setValue('example@abc.com')
    – Sarthak Aggarwal
    Nov 13 at 6:57












  • What u mean? How?
    – Banujan Balendrakumar
    Nov 13 at 6:59










  • Please paste your code as text instead of screen shot
    – Amit Chigadani
    Nov 13 at 7:05










  • Sarthak Aggarwal Works thanks.
    – Banujan Balendrakumar
    Nov 13 at 7:06










  • angular.io/api/forms/AbstractControl#updatevalueandvalidity
    – Eliseo
    Nov 13 at 7:34















up vote
0
down vote

favorite












I am developing a small app in angular5 with PHP. I have an issue in validating form. Form validator works fine when I input data by typing in keyboard. But it is not working when I fill data with javascript.



For example



In email field,



If I type myemail , Its showing invalid email. works good.
But If I set using javascript like $('#email').value('asdsa@gmail.com') its not working.



Form



Validator



enter image description here



What is wrong? I am new to Angular5.










share|improve this question


















  • 3




    instead of directly manipulating DOM, try setting value of form control manually this.registerForm.controls['email'].setValue('example@abc.com')
    – Sarthak Aggarwal
    Nov 13 at 6:57












  • What u mean? How?
    – Banujan Balendrakumar
    Nov 13 at 6:59










  • Please paste your code as text instead of screen shot
    – Amit Chigadani
    Nov 13 at 7:05










  • Sarthak Aggarwal Works thanks.
    – Banujan Balendrakumar
    Nov 13 at 7:06










  • angular.io/api/forms/AbstractControl#updatevalueandvalidity
    – Eliseo
    Nov 13 at 7:34













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I am developing a small app in angular5 with PHP. I have an issue in validating form. Form validator works fine when I input data by typing in keyboard. But it is not working when I fill data with javascript.



For example



In email field,



If I type myemail , Its showing invalid email. works good.
But If I set using javascript like $('#email').value('asdsa@gmail.com') its not working.



Form



Validator



enter image description here



What is wrong? I am new to Angular5.










share|improve this question













I am developing a small app in angular5 with PHP. I have an issue in validating form. Form validator works fine when I input data by typing in keyboard. But it is not working when I fill data with javascript.



For example



In email field,



If I type myemail , Its showing invalid email. works good.
But If I set using javascript like $('#email').value('asdsa@gmail.com') its not working.



Form



Validator



enter image description here



What is wrong? I am new to Angular5.







javascript html angular






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 13 at 6:55









Banujan Balendrakumar

274110




274110








  • 3




    instead of directly manipulating DOM, try setting value of form control manually this.registerForm.controls['email'].setValue('example@abc.com')
    – Sarthak Aggarwal
    Nov 13 at 6:57












  • What u mean? How?
    – Banujan Balendrakumar
    Nov 13 at 6:59










  • Please paste your code as text instead of screen shot
    – Amit Chigadani
    Nov 13 at 7:05










  • Sarthak Aggarwal Works thanks.
    – Banujan Balendrakumar
    Nov 13 at 7:06










  • angular.io/api/forms/AbstractControl#updatevalueandvalidity
    – Eliseo
    Nov 13 at 7:34














  • 3




    instead of directly manipulating DOM, try setting value of form control manually this.registerForm.controls['email'].setValue('example@abc.com')
    – Sarthak Aggarwal
    Nov 13 at 6:57












  • What u mean? How?
    – Banujan Balendrakumar
    Nov 13 at 6:59










  • Please paste your code as text instead of screen shot
    – Amit Chigadani
    Nov 13 at 7:05










  • Sarthak Aggarwal Works thanks.
    – Banujan Balendrakumar
    Nov 13 at 7:06










  • angular.io/api/forms/AbstractControl#updatevalueandvalidity
    – Eliseo
    Nov 13 at 7:34








3




3




instead of directly manipulating DOM, try setting value of form control manually this.registerForm.controls['email'].setValue('example@abc.com')
– Sarthak Aggarwal
Nov 13 at 6:57






instead of directly manipulating DOM, try setting value of form control manually this.registerForm.controls['email'].setValue('example@abc.com')
– Sarthak Aggarwal
Nov 13 at 6:57














What u mean? How?
– Banujan Balendrakumar
Nov 13 at 6:59




What u mean? How?
– Banujan Balendrakumar
Nov 13 at 6:59












Please paste your code as text instead of screen shot
– Amit Chigadani
Nov 13 at 7:05




Please paste your code as text instead of screen shot
– Amit Chigadani
Nov 13 at 7:05












Sarthak Aggarwal Works thanks.
– Banujan Balendrakumar
Nov 13 at 7:06




Sarthak Aggarwal Works thanks.
– Banujan Balendrakumar
Nov 13 at 7:06












angular.io/api/forms/AbstractControl#updatevalueandvalidity
– Eliseo
Nov 13 at 7:34




angular.io/api/forms/AbstractControl#updatevalueandvalidity
– Eliseo
Nov 13 at 7:34












3 Answers
3






active

oldest

votes

















up vote
1
down vote



accepted










try to use below code for setting up the value in the form control. pleas refer angular doc for more information https://angular.io/guide/form-validation
https://angular.io/guide/reactive-forms



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



this.registerForm.controls.email.setValue('asdsa@gmail.com');







share|improve this answer




























    up vote
    0
    down vote













    You can just say see this link



    this.registerForm.patchValue({
    email: 'asdsa@gmail.com'
    });


    or you can assign it initially while creating a form like,



    this.registerForm = this.fb.group({
    email: ['asdsa@gmail.com']
    })





    share|improve this answer






























      up vote
      0
      down vote













      If I remember correctly, angular does not know when jQuery affects the Physical DOM(therefore not knowing when to run its check on variables to cause a change). In order to do this, you have to initiate a change cycle to angular after your jquery action.






      share|improve this answer





















        Your Answer






        StackExchange.ifUsing("editor", function () {
        StackExchange.using("externalEditor", function () {
        StackExchange.using("snippets", function () {
        StackExchange.snippets.init();
        });
        });
        }, "code-snippets");

        StackExchange.ready(function() {
        var channelOptions = {
        tags: "".split(" "),
        id: "1"
        };
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function() {
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled) {
        StackExchange.using("snippets", function() {
        createEditor();
        });
        }
        else {
        createEditor();
        }
        });

        function createEditor() {
        StackExchange.prepareEditor({
        heartbeatType: 'answer',
        convertImagesToLinks: true,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: 10,
        bindNavPrevention: true,
        postfix: "",
        imageUploader: {
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        },
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        });


        }
        });














         

        draft saved


        draft discarded


















        StackExchange.ready(
        function () {
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53275415%2fangular-form-validator-only-works-when-typing-in-text-box%23new-answer', 'question_page');
        }
        );

        Post as a guest















        Required, but never shown

























        3 Answers
        3






        active

        oldest

        votes








        3 Answers
        3






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes








        up vote
        1
        down vote



        accepted










        try to use below code for setting up the value in the form control. pleas refer angular doc for more information https://angular.io/guide/form-validation
        https://angular.io/guide/reactive-forms



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



        this.registerForm.controls.email.setValue('asdsa@gmail.com');







        share|improve this answer

























          up vote
          1
          down vote



          accepted










          try to use below code for setting up the value in the form control. pleas refer angular doc for more information https://angular.io/guide/form-validation
          https://angular.io/guide/reactive-forms



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



          this.registerForm.controls.email.setValue('asdsa@gmail.com');







          share|improve this answer























            up vote
            1
            down vote



            accepted







            up vote
            1
            down vote



            accepted






            try to use below code for setting up the value in the form control. pleas refer angular doc for more information https://angular.io/guide/form-validation
            https://angular.io/guide/reactive-forms



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



            this.registerForm.controls.email.setValue('asdsa@gmail.com');







            share|improve this answer












            try to use below code for setting up the value in the form control. pleas refer angular doc for more information https://angular.io/guide/form-validation
            https://angular.io/guide/reactive-forms



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



            this.registerForm.controls.email.setValue('asdsa@gmail.com');








            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 13 at 7:00









            Ajay Ojha

            94027




            94027
























                up vote
                0
                down vote













                You can just say see this link



                this.registerForm.patchValue({
                email: 'asdsa@gmail.com'
                });


                or you can assign it initially while creating a form like,



                this.registerForm = this.fb.group({
                email: ['asdsa@gmail.com']
                })





                share|improve this answer



























                  up vote
                  0
                  down vote













                  You can just say see this link



                  this.registerForm.patchValue({
                  email: 'asdsa@gmail.com'
                  });


                  or you can assign it initially while creating a form like,



                  this.registerForm = this.fb.group({
                  email: ['asdsa@gmail.com']
                  })





                  share|improve this answer

























                    up vote
                    0
                    down vote










                    up vote
                    0
                    down vote









                    You can just say see this link



                    this.registerForm.patchValue({
                    email: 'asdsa@gmail.com'
                    });


                    or you can assign it initially while creating a form like,



                    this.registerForm = this.fb.group({
                    email: ['asdsa@gmail.com']
                    })





                    share|improve this answer














                    You can just say see this link



                    this.registerForm.patchValue({
                    email: 'asdsa@gmail.com'
                    });


                    or you can assign it initially while creating a form like,



                    this.registerForm = this.fb.group({
                    email: ['asdsa@gmail.com']
                    })






                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Nov 13 at 7:07

























                    answered Nov 13 at 7:01









                    Abhishek Ekaanth

                    882923




                    882923






















                        up vote
                        0
                        down vote













                        If I remember correctly, angular does not know when jQuery affects the Physical DOM(therefore not knowing when to run its check on variables to cause a change). In order to do this, you have to initiate a change cycle to angular after your jquery action.






                        share|improve this answer

























                          up vote
                          0
                          down vote













                          If I remember correctly, angular does not know when jQuery affects the Physical DOM(therefore not knowing when to run its check on variables to cause a change). In order to do this, you have to initiate a change cycle to angular after your jquery action.






                          share|improve this answer























                            up vote
                            0
                            down vote










                            up vote
                            0
                            down vote









                            If I remember correctly, angular does not know when jQuery affects the Physical DOM(therefore not knowing when to run its check on variables to cause a change). In order to do this, you have to initiate a change cycle to angular after your jquery action.






                            share|improve this answer












                            If I remember correctly, angular does not know when jQuery affects the Physical DOM(therefore not knowing when to run its check on variables to cause a change). In order to do this, you have to initiate a change cycle to angular after your jquery action.







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Nov 13 at 7:14









                            Minh Nguyen

                            645




                            645






























                                 

                                draft saved


                                draft discarded



















































                                 


                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function () {
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53275415%2fangular-form-validator-only-works-when-typing-in-text-box%23new-answer', 'question_page');
                                }
                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown







                                Popular posts from this blog

                                Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

                                ComboBox Display Member on multiple fields

                                Is it possible to collect Nectar points via Trainline?