Bean0341
Bean0341

Reputation: 1697

Angular 2 Form Required validation fires after submit

I have created a form that creates a sort of social media Post. The problem is that after all the fields are filled out, and I hit submit, the validation still fires after the post is submitted. I have been looking through the angular 2 docs and there doesn't seem to be any talk about this happening. I cant accept a hack for this fix. Is there something wrong with my form? or did I miss something in the docs when discussing the required call. Below is my plunker with the issue, thank you for any help in advance.

plunker

Upvotes: 0

Views: 122

Answers (1)

Tân
Tân

Reputation: 1

addPost(post){
        if(this.newPost != null && 
            post &&
            this.newPost.title.length>=1 &&
            this.newPost.description.length>=1){
                this.posts.unshift(this.newPost);
                this.newPost = new Post();
                return false // add this line
        }
    }

Edit: adding return false at the end in if block.

Upvotes: 1

Related Questions