0

I want to disable DOB field to prevent from edit and also I want to disable gender radio button for second time, if once user select gender and submit it then next time if he want edit profile and want to change gender so that time it should be disable. how can I achieve it.

I have tired this way but not working

<div class="form-group label-floating"> <label class="control-label " for="name">Date of Birth</label> <input type="text" class="form-control" formControlName='dob' id='dob' value="{{ dob | date:'dd-MMM-yyyy' }}" [readonly]="true"> <!-- <app-field-error-display [displayError]="this.validationService.isFieldValid(updateProfileForm,'dob')"> </app-field-error-display> --> <span class='error-msg'></span> </div> <div class="form-group label-floating"> <label class="control-label " for="name">Date of Birth</label> <input type="text" class="form-control" formControlName='dob' id='dob' value="{{ dob | date:'dd-MMM-yyyy' }}" [disable]="true"> <!-- <app-field-error-display [displayError]="this.validationService.isFieldValid(updateProfileForm,'dob')"> </app-field-error-display> --> <span class='error-msg'></span> </div> `

                                <label class="radio-inline">
                                    <span class="control-label gender_row">Gender&nbsp;</span>
                                    <input [disabled]="true" type="radio" name="gender" value="1" formControlName='gender'  [checked]="gender==1">Male
                                </label>
                                <label class="radio-inline">
                                    <input type="radio" name="gender" value="2" formControlName='gender' [checked]="gender==2">Female
                                </label>
                                <!-- <label class="radio-inline">
                                    <input type="radio" name="gender" value="3" formControlName='gender' [checked]="gender===3">Other
                                </label> -->
                                <label class="radio-inline">
                                    <input type="radio" name="gender" value="3" formControlName='gender' [checked]="gender==3">Don't want to disclose
                                </label>

                            </div>`

this the my view looks like enter image description here

For DOB field I want to disable forever but gender field I want disable for second time.once user submit profile.

3
  • did you try to declare a variable submitted in component and set [disabled]="invalide && submitted" ? Commented Mar 26, 2019 at 11:36
  • @HienNguyen I have few fields in user profile but if user once select gender and submit it so it should be disabled for next time to edit Commented Mar 26, 2019 at 11:55
  • @HienNguyen Please can explain me little bit Commented Mar 26, 2019 at 12:25

1 Answer 1

1

You can set the [disabled] attribute to true if the value is filled for the radio buttons, and the [readonly] attribute to true the same way.

<input type="date" [readonly]="!!birthdate" formControlName="birthdate">

Sign up to request clarification or add additional context in comments.

3 Comments

Even I don't wan to open datepicker
I'm sorry, where are you triggering the opening of a datepicker?
ok no issue I will look at this one myself but I have few fields in user profile but if user once select gender and submit it so it should be disabled for next time to edit

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.