Remove template based Validation after input element removed from html in angular2019 Community Moderator ElectionWhat is the Angular 2 RC5 way of writing template based forms?Nested forms in Angular 2 JS (RC4 and newer)How to move *ngIf conditions from template to typescript file in angular 2angular2 - validating FormControlName in child component of parent FormGroupAngular2 reactive forms, how to pass FormGroup and FormArray to sub componentAdd/remove reactive form validators to dynamically created inputsAngular FormArray: referencing dynamically added FormControl in templateAngular 5 reactive forms custom control inconsistent validation state on conditionally add/remove from DOMConditional required validation and numeric, alpha validation in Angular Template Driven FormHow to wrap angular material form into a component & expose them to FormGroup as a formControl element

What was the implant device Captain Marvel was using?

School performs periodic password audits. Is my password compromised?

How does NOW work?

How to detect if C code (which needs 'extern C') is compiled in C++

How can I ensure my trip to the UK will not have to be cancelled because of Brexit?

Rewrite the power sum in terms of convolution

In the quantum hamiltonian, why does kinetic energy turn into an operator while potential doesn't?

Are babies of evil humanoid species inherently evil?

At what distance can a bugbear, holding a reach weapon, with Polearm Mastery, get their Opportunity Attack?

Why was Goose renamed from Chewie for the Captain Marvel film?

Can I pump my MTB tire to max (55 psi / 380 kPa) without the tube inside bursting?

Accepted offer letter, position changed

How strictly should I take "Candidates must be local"?

Can you reject a postdoc offer after the PI has paid a large sum for flights/accommodation for your visit?

When a wind turbine does not produce enough electricity how does the power company compensate for the loss?

Intuition behind counterexample of Euler's sum of powers conjecture

Reversed Sudoku

Expressing logarithmic equations without logs

NASA's RS-25 Engines shut down time

Can one live in the U.S. and not use a credit card?

PTIJ: Should I kill my computer after installing software?

List elements digit difference sort

What is the cause of the Apocalypse in The Umbrella Academy?

Is "history" a male-biased word ("his+story")?



Remove template based Validation after input element removed from html in angular



2019 Community Moderator ElectionWhat is the Angular 2 RC5 way of writing template based forms?Nested forms in Angular 2 JS (RC4 and newer)How to move *ngIf conditions from template to typescript file in angular 2angular2 - validating FormControlName in child component of parent FormGroupAngular2 reactive forms, how to pass FormGroup and FormArray to sub componentAdd/remove reactive form validators to dynamically created inputsAngular FormArray: referencing dynamically added FormControl in templateAngular 5 reactive forms custom control inconsistent validation state on conditionally add/remove from DOMConditional required validation and numeric, alpha validation in Angular Template Driven FormHow to wrap angular material form into a component & expose them to FormGroup as a formControl element










0















I wanting to do validation based on input flag, But unfortunately it fails my validation. If i use template validation it fails or if i use Form Validation it works. But for satisfying my requirement i need to use template based validation.



Below is code and screen shot



import Component from '@angular/core';
import FormControl, FormGroup from '@angular/forms';

@Component(
selector: 'my-app',
template: `
<h1>Angular Sample </h1>
<form [formGroup]="countryForm">
<input type="checkbox"
formControlName="city" /> Is Other City
<ng-container *ngIf='countryForm.value.city'>
<hr />
<label>City : </label>
<input
required='true'
placeholder="Enter city Name"
formControlName="cityName" />
</ng-container>
<hr />
<button [disabled]="countryForm.invalid">Submit</button>
</form>
`
)
export class AppComponent

countryForm: FormGroup = new FormGroup(
city: new FormControl(),
cityName: new FormControl(),
);
constructor()



Step 001



Step 002



Step 003



Step 004










share|improve this question






















  • What is the issue?

    – Chellappan
    Mar 7 at 6:57











  • Valid Flag is not updating after disappear city Name from UI.

    – Hamid Raza Noori
    Mar 7 at 8:20















0















I wanting to do validation based on input flag, But unfortunately it fails my validation. If i use template validation it fails or if i use Form Validation it works. But for satisfying my requirement i need to use template based validation.



Below is code and screen shot



import Component from '@angular/core';
import FormControl, FormGroup from '@angular/forms';

@Component(
selector: 'my-app',
template: `
<h1>Angular Sample </h1>
<form [formGroup]="countryForm">
<input type="checkbox"
formControlName="city" /> Is Other City
<ng-container *ngIf='countryForm.value.city'>
<hr />
<label>City : </label>
<input
required='true'
placeholder="Enter city Name"
formControlName="cityName" />
</ng-container>
<hr />
<button [disabled]="countryForm.invalid">Submit</button>
</form>
`
)
export class AppComponent

countryForm: FormGroup = new FormGroup(
city: new FormControl(),
cityName: new FormControl(),
);
constructor()



Step 001



Step 002



Step 003



Step 004










share|improve this question






















  • What is the issue?

    – Chellappan
    Mar 7 at 6:57











  • Valid Flag is not updating after disappear city Name from UI.

    – Hamid Raza Noori
    Mar 7 at 8:20













0












0








0








I wanting to do validation based on input flag, But unfortunately it fails my validation. If i use template validation it fails or if i use Form Validation it works. But for satisfying my requirement i need to use template based validation.



Below is code and screen shot



import Component from '@angular/core';
import FormControl, FormGroup from '@angular/forms';

@Component(
selector: 'my-app',
template: `
<h1>Angular Sample </h1>
<form [formGroup]="countryForm">
<input type="checkbox"
formControlName="city" /> Is Other City
<ng-container *ngIf='countryForm.value.city'>
<hr />
<label>City : </label>
<input
required='true'
placeholder="Enter city Name"
formControlName="cityName" />
</ng-container>
<hr />
<button [disabled]="countryForm.invalid">Submit</button>
</form>
`
)
export class AppComponent

countryForm: FormGroup = new FormGroup(
city: new FormControl(),
cityName: new FormControl(),
);
constructor()



Step 001



Step 002



Step 003



Step 004










share|improve this question














I wanting to do validation based on input flag, But unfortunately it fails my validation. If i use template validation it fails or if i use Form Validation it works. But for satisfying my requirement i need to use template based validation.



Below is code and screen shot



import Component from '@angular/core';
import FormControl, FormGroup from '@angular/forms';

@Component(
selector: 'my-app',
template: `
<h1>Angular Sample </h1>
<form [formGroup]="countryForm">
<input type="checkbox"
formControlName="city" /> Is Other City
<ng-container *ngIf='countryForm.value.city'>
<hr />
<label>City : </label>
<input
required='true'
placeholder="Enter city Name"
formControlName="cityName" />
</ng-container>
<hr />
<button [disabled]="countryForm.invalid">Submit</button>
</form>
`
)
export class AppComponent

countryForm: FormGroup = new FormGroup(
city: new FormControl(),
cityName: new FormControl(),
);
constructor()



Step 001



Step 002



Step 003



Step 004







angular angular6






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 7 at 6:24









Hamid Raza NooriHamid Raza Noori

4212




4212












  • What is the issue?

    – Chellappan
    Mar 7 at 6:57











  • Valid Flag is not updating after disappear city Name from UI.

    – Hamid Raza Noori
    Mar 7 at 8:20

















  • What is the issue?

    – Chellappan
    Mar 7 at 6:57











  • Valid Flag is not updating after disappear city Name from UI.

    – Hamid Raza Noori
    Mar 7 at 8:20
















What is the issue?

– Chellappan
Mar 7 at 6:57





What is the issue?

– Chellappan
Mar 7 at 6:57













Valid Flag is not updating after disappear city Name from UI.

– Hamid Raza Noori
Mar 7 at 8:20





Valid Flag is not updating after disappear city Name from UI.

– Hamid Raza Noori
Mar 7 at 8:20












1 Answer
1






active

oldest

votes


















0














You can enable/disable a form control by using Instantiate a new FormControl with the disabled property set to true. FormControl(value: '', disabled: true)



Then Using control.disable() or control.enable() method to enable or disable, method as per your need.



app.component.ts



constructor() 
this.countryForm = new FormGroup(
city: new FormControl(),
cityName: new FormControl( value: '', disabled: false ),
);


this.countryForm.get('city').valueChanges.subscribe(v =>
v ? this.countryForm.get('cityName').enable() : this.countryForm.get('cityName').disable();
)



Example:https://stackblitz.com/edit/stack-overflowexample






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',
    autoActivateHeartbeat: false,
    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%2f55037304%2fremove-template-based-validation-after-input-element-removed-from-html-in-angula%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    You can enable/disable a form control by using Instantiate a new FormControl with the disabled property set to true. FormControl(value: '', disabled: true)



    Then Using control.disable() or control.enable() method to enable or disable, method as per your need.



    app.component.ts



    constructor() 
    this.countryForm = new FormGroup(
    city: new FormControl(),
    cityName: new FormControl( value: '', disabled: false ),
    );


    this.countryForm.get('city').valueChanges.subscribe(v =>
    v ? this.countryForm.get('cityName').enable() : this.countryForm.get('cityName').disable();
    )



    Example:https://stackblitz.com/edit/stack-overflowexample






    share|improve this answer



























      0














      You can enable/disable a form control by using Instantiate a new FormControl with the disabled property set to true. FormControl(value: '', disabled: true)



      Then Using control.disable() or control.enable() method to enable or disable, method as per your need.



      app.component.ts



      constructor() 
      this.countryForm = new FormGroup(
      city: new FormControl(),
      cityName: new FormControl( value: '', disabled: false ),
      );


      this.countryForm.get('city').valueChanges.subscribe(v =>
      v ? this.countryForm.get('cityName').enable() : this.countryForm.get('cityName').disable();
      )



      Example:https://stackblitz.com/edit/stack-overflowexample






      share|improve this answer

























        0












        0








        0







        You can enable/disable a form control by using Instantiate a new FormControl with the disabled property set to true. FormControl(value: '', disabled: true)



        Then Using control.disable() or control.enable() method to enable or disable, method as per your need.



        app.component.ts



        constructor() 
        this.countryForm = new FormGroup(
        city: new FormControl(),
        cityName: new FormControl( value: '', disabled: false ),
        );


        this.countryForm.get('city').valueChanges.subscribe(v =>
        v ? this.countryForm.get('cityName').enable() : this.countryForm.get('cityName').disable();
        )



        Example:https://stackblitz.com/edit/stack-overflowexample






        share|improve this answer













        You can enable/disable a form control by using Instantiate a new FormControl with the disabled property set to true. FormControl(value: '', disabled: true)



        Then Using control.disable() or control.enable() method to enable or disable, method as per your need.



        app.component.ts



        constructor() 
        this.countryForm = new FormGroup(
        city: new FormControl(),
        cityName: new FormControl( value: '', disabled: false ),
        );


        this.countryForm.get('city').valueChanges.subscribe(v =>
        v ? this.countryForm.get('cityName').enable() : this.countryForm.get('cityName').disable();
        )



        Example:https://stackblitz.com/edit/stack-overflowexample







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 7 at 9:04









        ChellappanChellappan

        5,5862420




        5,5862420





























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55037304%2fremove-template-based-validation-after-input-element-removed-from-html-in-angula%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

            How to get text form Clipboard with JavaScript in Firefox 56?How to validate an email address in JavaScript?How do JavaScript closures work?How do I remove a property from a JavaScript object?How do you get a timestamp in JavaScript?How do I copy to the clipboard in JavaScript?How do I include a JavaScript file in another JavaScript file?Get the current URL with JavaScript?How to replace all occurrences of a string in JavaScriptHow to check whether a string contains a substring in JavaScript?How do I remove a particular element from an array in JavaScript?

            Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

            List of MPs elected to the English parliament in 1640 (April) Contents List of constituencies and members See also Notes References Navigation menueNational Archives – The Glynde Place ArchivesCobbett's Parliamentary history of England, from the Norman Conquest in 1066 to the year 1803'Aldermen in Parliament', The Aldermen of the City of London: Temp. Henry III – 1912onepage&q&f&#61, false 229