পৃষ্ঠাসমূহ

Search Your Article

CS

 

Welcome to GoogleDG – your one-stop destination for free learning resources, guides, and digital tools.

At GoogleDG, we believe that knowledge should be accessible to everyone. Our mission is to provide readers with valuable ebooks, tutorials, and tech-related content that makes learning easier, faster, and more enjoyable.

What We Offer:

  • 📘 Free & Helpful Ebooks – covering education, technology, self-development, and more.

  • 💻 Step-by-Step Tutorials – practical guides on digital tools, apps, and software.

  • 🌐 Tech Updates & Tips – simplified information to keep you informed in the fast-changing digital world.

  • 🎯 Learning Support – resources designed to support students, professionals, and lifelong learners.

    Latest world News 

     

Our Vision

To create a digital knowledge hub where anyone, from beginners to advanced learners, can find trustworthy resources and grow their skills.

Why Choose Us?

✔ Simple explanations of complex topics
✔ 100% free access to resources
✔ Regularly updated content
✔ A community that values knowledge sharing

We are continuously working to expand our content library and provide readers with the most useful and relevant digital learning materials.

📩 If you’d like to connect, share feedback, or suggest topics, feel free to reach us through the Contact page.

Pageviews

Monday, February 13, 2017

Aurelia - Forms

In this chapter we will show you who to use forms in Aurelia framework.

Text Input

First we will see how to submit an input form. The view will have two input forms for username and password. We will use value.bind for data binding.

app.html

<template>  

   <form role = "form" submit.delegate = "signup()">

      <label for = "email">Email</label>
      <input type = "text" value.bind = "email" placeholder = "Email">

      <label for = "password">Password</label>
      <input type = "password" value.bind = "password" placeholder = "Password">

      <button type = "submit">Signup</button>
   </form>

</template>
The signup function will just take username and password values from the inputs and log it in developers console.
export class App {

   email = '';
   password = '';

   signup() {
      var myUser = { email: this.email, password: this.password }
      console.log(myUser);
   };
  
}
Aurelia Forms Input

Checkbox

The next example will show how to submit a checkbox with Aurelia framework. We will create one checkbox and bind checked value to our view-model.

app.html

<template>
  
   <form role = "form" submit.delegate = "submit()">
      <label for = "checkbox">Checkbox</label>
      <input type = "checkbox" id = "checkbox" checked.bind = "isChecked"><br/>
      <button type = "submit">SUBMIT</button>   
   </form>

</template>
Form submitting will just log checked value in console.

app.js

export class App  {
   constructor() {
      this.isChecked = false;
   }
  
   submit(){
      console.log("isChecked: " + this.isChecked);
   }
}
Aurelia Forms Checkbox

Radio Buttons

The last example from this chapter will show you how to submit radio buttons. The syntax repeat.for="option of options" will repeat through array of objects and create radio button for each object. This is neat way of dynamically creating elements in Aurelia framework. The rest is the same as in previous examples. We are binding model and checked values.

app.html

<template>
   <form role = "form" submit.delegate = "submit()">
 
      <label repeat.for = "option of options">
         <input type = "radio" name = "myOptions" 
            model.bind = "option" checked.bind = "$parent.selectedOption"/>
            ${option.text}
      </label><br/>
  
      <button type = "submit">SUBMIT</button>
   </form>
</template>
In our view-model we will create array of objects this.options and specify that the first radio button is checked. Again, SUBMIT button will just log in console which radio button is checked.

app.js

export class PeriodPanel {
   options = [];
   selectedOption = {};

   constructor() {
      this.options = [
         {id:1, text:'First'}, 
         {id:2, text:'Second'}, 
         {id:3, text:'Third'}
      ]; 
      this.selectedOption = this.options[0];
   }

   submit() {
      console.log('checked: ' + this.selectedOption.id);
   }
}
If we check third radio button and submit our form, the console will show it.
Aurelia Forms Radio

No comments:

Post a Comment