Can you require two form fields to match with HTML?

Not exactly with HTML validation but a little JavaScript can resolve the issue, follow the example below: function check() { var input = document.getElementById(‘password_confirm’); if (input.value != document.getElementById(‘password’).value) { input.setCustomValidity(‘Password Must be Matching.’); } else { // input is valid — reset the error message input.setCustomValidity(”); } } <p> <label for=”password”>Password:</label> <input name=”password” required=”required” type=”password” …

Read more

Symfony2 Setting a default choice field selection

You can define the default value from the ‘data’ attribute. This is part of the Abstract “field” type ( $form = $this->createFormBuilder() ->add(‘status’, ‘choice’, array( ‘choices’ => array( 0 => ‘Published’, 1 => ‘Draft’ ), ‘data’ => 1 )) ->getForm(); In this example, ‘Draft’ would be set as the default selected value.

Input type number “only numeric value” validation

In the HTML file, you can add ngIf for your pattern like this, <div class=”form-control-feedback” *ngIf=”Mobile.errors && (Mobile.dirty || Mobile.touched)”> <p *ngIf=”Mobile.errors.pattern” class=”text-danger”>Number Only</p> </div> In .ts file you can add the Validators pattern –”^[0-9]*$” this.Mobile = new FormControl(”, [ Validators.required, Validators.pattern(“^[0-9]*$”), Validators.minLength(8), ]);

How to use formControlName and deal with nested formGroup?

you can use Form group which is basically a collection of controls ( controls mean the fields given in your html form) define in your typescript syntax and binded to your HTML elements using the formControlName directive ,for example this.myForm ={ ‘fullname’: [”, Validators.required], ‘gender’: [], ‘address’:{ ‘street’: [”], ‘houseNumber’: [”], ‘postalCode’: [”] …

Read more