Watch Properties

7 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$69.99
List Price:  $99.99
You save:  $30
€65.59
List Price:  €93.70
You save:  €28.11
£56.03
List Price:  £80.05
You save:  £24.01
CA$96.39
List Price:  CA$137.71
You save:  CA$41.31
A$107.98
List Price:  A$154.26
You save:  A$46.28
S$95.50
List Price:  S$136.44
You save:  S$40.93
HK$547.57
List Price:  HK$782.28
You save:  HK$234.70
CHF 64.43
List Price:  CHF 92.05
You save:  CHF 27.61
NOK kr776.82
List Price:  NOK kr1,109.79
You save:  NOK kr332.97
DKK kr489.21
List Price:  DKK kr698.91
You save:  DKK kr209.69
NZ$118.81
List Price:  NZ$169.74
You save:  NZ$50.92
د.إ257.06
List Price:  د.إ367.25
You save:  د.إ110.18
৳7,729.18
List Price:  ৳11,042.16
You save:  ৳3,312.97
₹5,842.93
List Price:  ₹8,347.41
You save:  ₹2,504.47
RM333.67
List Price:  RM476.70
You save:  RM143.02
₦92,745.84
List Price:  ₦132,499.74
You save:  ₦39,753.90
₨19,599.98
List Price:  ₨28,001.17
You save:  ₨8,401.19
฿2,600.12
List Price:  ฿3,714.62
You save:  ฿1,114.50
₺2,271.31
List Price:  ₺3,244.87
You save:  ₺973.56
B$363.64
List Price:  B$519.51
You save:  B$155.87
R1,308.28
List Price:  R1,869.05
You save:  R560.77
Лв128.30
List Price:  Лв183.29
You save:  Лв54.99
₩96,996.60
List Price:  ₩138,572.52
You save:  ₩41,575.91
₪261.41
List Price:  ₪373.46
You save:  ₪112.04
₱4,045.59
List Price:  ₱5,779.67
You save:  ₱1,734.07
¥11,052.75
List Price:  ¥15,790.32
You save:  ¥4,737.57
MX$1,197.81
List Price:  MX$1,711.23
You save:  MX$513.42
QR257.31
List Price:  QR367.61
You save:  QR110.29
P1,000.11
List Price:  P1,428.79
You save:  P428.68
KSh9,335.98
List Price:  KSh13,337.69
You save:  KSh4,001.70
E£3,349.95
List Price:  E£4,785.86
You save:  E£1,435.90
ብር4,013.63
List Price:  ብር5,734.01
You save:  ብር1,720.37
Kz58,409.45
List Price:  Kz83,445.65
You save:  Kz25,036.20
CLP$67,298.07
List Price:  CLP$96,144.23
You save:  CLP$28,846.15
CN¥506.79
List Price:  CN¥724.02
You save:  CN¥217.23
RD$4,121.81
List Price:  RD$5,888.55
You save:  RD$1,766.74
DA9,423.87
List Price:  DA13,463.25
You save:  DA4,039.38
FJ$159.96
List Price:  FJ$228.52
You save:  FJ$68.56
Q547.38
List Price:  Q782
You save:  Q234.62
GY$14,742.16
List Price:  GY$21,061.13
You save:  GY$6,318.97
ISK kr9,832.89
List Price:  ISK kr14,047.59
You save:  ISK kr4,214.70
DH712.24
List Price:  DH1,017.53
You save:  DH305.29
L1,243.01
List Price:  L1,775.81
You save:  L532.79
ден4,046.68
List Price:  ден5,781.23
You save:  ден1,734.54
MOP$564.08
List Price:  MOP$805.87
You save:  MOP$241.78
N$1,315.96
List Price:  N$1,880.02
You save:  N$564.06
C$2,592.36
List Price:  C$3,703.54
You save:  C$1,111.17
रु9,349.94
List Price:  रु13,357.63
You save:  रु4,007.69
S/263.70
List Price:  S/376.73
You save:  S/113.03
K271.96
List Price:  K388.53
You save:  K116.57
SAR262.49
List Price:  SAR375.01
You save:  SAR112.51
ZK1,886.12
List Price:  ZK2,694.57
You save:  ZK808.45
L326.39
List Price:  L466.29
You save:  L139.90
Kč1,650.20
List Price:  Kč2,357.53
You save:  Kč707.33
Ft25,629.21
List Price:  Ft36,614.73
You save:  Ft10,985.52
SEK kr770.71
List Price:  SEK kr1,101.06
You save:  SEK kr330.35
ARS$61,698.11
List Price:  ARS$88,143.94
You save:  ARS$26,445.82
Bs486.86
List Price:  Bs695.54
You save:  Bs208.68
COP$271,471.23
List Price:  COP$387,832.67
You save:  COP$116,361.43
₡35,819.54
List Price:  ₡51,172.97
You save:  ₡15,353.42
L1,740.31
List Price:  L2,486.27
You save:  L745.95
₲526,285.13
List Price:  ₲751,868.13
You save:  ₲225,582.99
$U2,699.91
List Price:  $U3,857.19
You save:  $U1,157.27
zł284.80
List Price:  zł406.88
You save:  zł122.07
Already have an account? Log In

Transcript

Welcome to another lecture in this lecture, we'll look into watch properties. But before we go any further, in the previous lecture mouse events have made some changes to the code and have updated them into the GitHub. So what the essentially what a genius have done is have separated the mouse events into its own individual div and now just correct them individually and each of them have given them their own methods, alright. So for example, this is the mouse up, this is mouse down, this is mouse Enter, and this should be mouse leave, and so on is the mouse move. Alright. So instead of having them all in one dip for your clarity and understanding, I just divided them into different methods divs and stylesheets and stylings.

Alright, so all right, we have a clean template. So basically, Water Watch properties. So in order to understand what properties you can kind of like imagine them as event listeners. So let's say you have a data property right? And you want to listen or watch the changes that will happen to the data property. You can use the watch property, watch properties would be much more useful for form validations when you can evaluate the validity of the data in real time.

So let's have an example. So we can understand much more better. So what we'll do is we'll create a small form. Inside this form, we can have two input variables. Let's use placeholder Alright, suppose let us say this is a signup form. And for the users to register, the username should be more than 10 characters.

And the password should be more than eight characters. All right. So one way what we could do is we could have two messages. All right. So these messages, I can show them right beside the input piece. So the reason why I'm putting these messages right beside the input fields is, I just want to know how many characters that are left, right.

So usually it would be. And for password, it's a guy just left. So if I save it, we can see username has 10 characters left and password has eight characters left. I'm sorry, we need two more variables to store the input fields. So let's say username and password. And we'll quickly bind them to these input fields using the model.

And this one is password, right? So whatever the whatever the text I'm inputting into these fields will be stored automatically to the username and password. So now I want to monitor These two data properties or you know, now I want to watch these two data properties, to understand the length of them and, and to make sure that they are at least 10 characters long. Or if it's password, it's eight characters long. So what I can do is, I can create another property called as watch. It also follows the syntax of an object.

So instead of the watch properties, I can directly use the data properties as a method, right? So let's say I have a username, right? I say username. And say it's a method. So what this syntax essentially does is this data property is being watched. Right?

It's, it's kind of like attaching an eventlistener to variable right? So inside username, for example, what we'll do is console dot log, this dot username. So whenever the data property username is being changed the watch property, what is the data property and whenever Something changes, it outputs us, or it triggers this method, right. So for example, if we open the console log, and if I'm typing anything, you can see whatever a type is being outputted onto the console log. So far removed, blank. Alright, so what we can do is with the help of this, since username is a string, we can output the length of it.

So I'm going to console log it. So if I save it, and I start typing, I can see that the length of the string starts to appear here. So now what we can do is to achieve our desired effect for the form. We can say this stored using a message equal to 10 minus this dot username Plus left. So every single time the username property changes, this gets recalculated. So the length of the username is calculated, and it is subtracted from 10.

And are added the string characters left. And this one is written to the data property username message. So if I save it, and I go out, so as I'm typing, you can see that the number of characters left decreases. So I can just add a small space here if I can. Yeah. So now it's going to negative four means which means the length of the username is much more greater than 10.

So what if we want to restrict it only to 10 so we can add a small check that says, if a name dot length is greater than 10 alert If I save this and also what we can also do is we also have this message. And if I save it, and I go back, as I'm typing, I still have four characters left. And if I exceeded there is an alert All right. So, you can also do the same thing with password or you can also make sure that once the username and password have matched the right amount of terms you can submit the form automatically or that would not be that would not be actually practical, but you can do many more cool stuff with it. And you can also try to add an input events to this form like to kind of like create much more intuitive experience to or to make the user understand like whatever is happening.

So most websites can have like uses watch properties and input events to kind of like as a means for mid form form validation. So whenever the user exits the input field or you know onblur input event is used can affect to understand If the format is right, or if while they're while they're typing, that they can find out if the length is right or if they're including any special characters. So that kind of stuff. So that's it for watch properties. I'll see you in the next one.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.