Setting up only two input fields side by side in an Angular Form

I'm fairly new to Angular development and currently working on creating a registration form. I need the form to have two columns in a row, with fields like Firstname and Lastname in one row, followed by Phone, Email, Password, and Confirm Password in the next row. I am using mat-form-field, but whenever I add a new field, they all end up being placed next to each other instead of moving to the next line as desired.

Check out the current form image here

component.html

<div class="container">
  <div class="row">
    <div class="registration-form col-md-6" style="max-width: -webkit-fill-available;">
      <div class="main-div" style="width: inherit;text-align: center">
        <div class="panel">
          <h2> Registration Form</h2>
        </div>
        <div class="alert alert-danger" *ngIf="errorMsg">
          {{errorMsg}}
        </div>
        <form #registartionForm="ngForm" (ngSubmit)="onSubmit()" novalidate>
          <mat-form-field appearance="outline">
            <mat-label>First Name</mat-label>
            <input matInput placeholder="Placeholder">
          </mat-form-field>
          &nbsp;
          <mat-form-field appearance="outline">
            <mat-label>Last Name</mat-label>
            <input matInput placeholder="Placeholder">
          </mat-form-field>
          &nbsp;
          <mat-form-field appearance="outline">
            <mat-label>Email</mat-label>
            <input matInput placeholder="Placeholder">
          </mat-form-field>
          &nbsp;
          <mat-form-field appearance="outline">
            <mat-label>Phone Number</mat-label>
            <input matInput placeholder="Placeholder">
          </mat-form-field>
          &nbsp;
          <mat-form-field appearance="outline">
            <mat-label>Password</mat-label>
            <input type="password" matInput placeholder="Placeholder">
          </mat-form-field>
          &nbsp;
          <mat-form-field appearance="outline">
            <mat-label>Confirm Password</mat-label>
            <input type="password" matInput placeholder="Placeholder">
          </mat-form-field>

        </form>
        <div>
          <button type="submit" class="btn btn-primary login" (click)="btnClick();">Register</button>
        </div>
      </div>
    </div>
  </div>
</div>

Your help is greatly appreciated. Thank you!

Answer №1

By utilizing Angular Material and enclosing each pair in a div, you can achieve the desired outcome. For a demonstration, visit https://stackblitz.com/edit/angular-qqrwni

<form #registartionForm="ngForm" (ngSubmit)="onSubmit()" novalidate >

          <div >
            <mat-form-field appearance="outline">
              <mat-label>First Name</mat-label>
              <input matInput placeholder="First Name">
            </mat-form-field>
            &nbsp;
            <mat-form-field appearance="outline">
              <mat-label>Last Name</mat-label>
              <input matInput placeholder="Last Name">
            </mat-form-field>
            &nbsp;
          </div>
          <div >
            <mat-form-field appearance="outline">
              <mat-label>Email</mat-label>
              <input matInput placeholder="Email">
            </mat-form-field>
            &nbsp;
            <mat-form-field appearance="outline">
              <mat-label>Phone Number</mat-label>
              <input matInput placeholder="Phone Number">
            </mat-form-field>
            &nbsp;
          </div>
          <div >
            <mat-form-field appearance="outline">
              <mat-label>Password</mat-label>
              <input type="password" matInput placeholder="Password">
            </mat-form-field>
            &nbsp;
            <mat-form-field appearance="outline">
              <mat-label>Confirm Password</mat-label>
              <input type="password" matInput placeholder="Confirm Password">
            </mat-form-field>
          </div>
        </form>

Answer №2

To enhance the layout of your webpage, consider utilizing bootstrap framework and inserting the following code snippet into your HTML file.

 <div class="container">
  <h1>Join Us</h1>
  <p>Kindly complete this form to sign up for an account.</p>
  <hr>
  <label for="email"><b>Email Address</b></label>
  <input type="text" placeholder="Enter Email Address" name="email" required>
  <label for="psw"><b>Password</b></label>
  <input type="password" placeholder="Choose a Password" name="psw" required>
  <label for="psw-repeat"><b>Confirm Password</b></label>
  <input type="password" placeholder="Repeat Password" name="psw-repeat" required>
  <button type="submit" class="registerbtn">Sign Up</button>
 </div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Learn the steps for submitting and interpreting information in Node Express

I am attempting to send this JSON data to a node express endpoint { "data": [ [ "Audit Territory", "LA Antelope Valley", "LA Central", "LA East San Gabriel", "LA San Fernando Valley", "LA West", ...

Rearrange HTML list items automatically according to changes in numeric sort order

I am working on a web page that features a dynamic ranked list. The items in the list are assigned a specific rank order number which changes based on user interactions elsewhere on the page. I have been exploring different options to automatically reorgan ...

Executing script once the DOM has completed loading

In my project, I'm dynamically generating menu items for a menu bar based on headers from external files that are imported using an XMLHttpRequest(). The menu bar is then updated as I navigate through different pages. Everything works smoothly. Each ...

Utilize Jquery to easily interact with RadComboBoxes

Is there a way to capture all RadComboBoxes change events in JQUERY for ASP.NET? $("input[type='text']").Change(function() { alert('changed'); }); In this example, I am specifying the input type as "text" because RadComboBoxes hav ...

Sharing information between Angular components

Having recently started using Angular, I'm facing an issue with passing an array to a different component that is not parent or child related. What I aim to achieve is: upon selecting rows from the first component table, a new view should open up disp ...

Retrieve JSON Data Using Angular in a Wordpress Environment

I need assistance with displaying a JSON Array in <li>'s within a Wordpress Template. Here is the specific JSON file: I am completely unfamiliar with how to achieve this. This is the HTML code I have: <div ng-app="appExtern" ng- ...

Creating a TypeScript type or interface that represents an object with one of many keys or simply a string

I am tasked with creating an interface that can either be a string or an object with one of three specific keys. The function I have takes care of different errors and returns the appropriate message: export const determineError = (error: ServerAlerts): ...

Encountering an Unexpected Token Error while using Jest in Next.js for node-modules

After setting up my Next.js project, I decided to install jest by running the command below: npm i --save-dev jest @testing-library/react @testing-library/jest-dom jest-environment-jsdom I then created a jest.config.json file with the following code snipp ...

Chrome's keyup event restricts the use of arrow keys in text fields

Could you please test this on Google Chrome browser: jQuery('#tien_cong').keyup(function(e) { jQuery(this).val(jQuery(this).val().replace(".", ",")); var sum = 0; var tien_cong = jQuery('#tien_cong').val(); tien_cong = tien_ ...

Ways to prevent a div containing a lengthy content string from extending beyond other divs

Check out my Codepen project here Here is the HTML code for my personal website: <div id="splash" class="divider"> <h1 class="text-center text-uppercase">vincent/rodomista</h1> <p class="text-center text uppercase">Full Stack ...

Having trouble with the alignment of CSS menu in Safari?

Can someone please assist me with a strange issue I am experiencing on my website? The menu appears misaligned when using Safari, and it's been driving me crazy. I've tried troubleshooting for hours without success. Here is a link to the site: I ...

Navigating from the Login Page to the Dashboard in Vue.js following successful token validation

I am facing an issue with the code that is supposed to redirect the User to the dashboard page if they have a token. Despite generating a JWT token from my Spring Boot backend and sending it to Vue for processing, the redirection is not working as expect ...

Tips for applying a CSS class with a smooth fade-out effect

In my Angular project, I am working on creating a custom notification component. Here is the template code I have so far: <aside *ngFor="let message of messages "> <div class="notification" style="position:fixed"> {{message.conten ...

Troubleshooting Problems with CSS `transform` in JQuery UI's `Slide` Transition

While implementing JQueryUI's slide transition on an element with a CSS transform, I encountered an issue where the top half of the element gets hidden during the animation. Is there a way to tweak either my JQueryUI animation or CSS to avoid this pro ...

Identify the nested Object within the Json data

I am looking to add and name a nested object within my Json data structure. The current structure of my Json is as follows: { "MH": [ { "MHF46": "Ledig", "MHF60": "60", }, ...

Tips on obtaining outcome by invoking a route outside of app.js

Within my file containing the request methods, the structure appears as follows: article.js router .route("/") .all((req, res) => { console.log("this should happen for any call to the article route"); }) .get((req, res) = ...

Managing touch devices and animations when hovering

Is there a way to remove or prevent all hover effects on a touch device? I've tried various scripts, but none seem to work for me. How can I test it with dev tools? I attempted this script but received an error: Cannot read property 'addEventList ...

Convert JavaScript code to Google Appscript

Looking for guidance on incorporating Javascript code into my Google Appscript. Here is the code snippet: I have a separate Stylesheet.html file saved. Can someone advise me on how to invoke the functions within the html file? <script> //google. ...

Incorporating Framer Motion into traditional React class components (non-functional approach)

I'm encountering an issue with a simple animation using Framer Motion that functions correctly in a functional component, but fails to work in a class component. I am new to Framer Motion and here is my react code => import {motion} from 'fr ...

I'm looking to configure @types for a third-party React JavaScript module in order to use it with TypeScript and bundle it with webpack. How can I accomplish this?

Imagine you have a third-party npm package called @foo that is all Javascript and has a module named bar. Within your TypeScript .tsx file, you want to use the React component @foo/bar/X. However, when you attempt to import X from '@foo/bar/X', y ...