02Geek HTML5 and JavaScript, TypeScript, React, Flash, ActionScript online School
Previous VideoNext Video

Everything we know intertwined

As always, we learn something new and then we integrate it. In this lesson, we continue the journey into creating our analyze Application. We're getting really close. In this lesson, we'll dive deeper into user interaction. We'll create and analyze what the user is doing, and based on it, change the application.

Video Transcript

00:01Congratulations! Congratulations because we are done learning new things for this
00:06chapter. In the next two lessons we're gonna practice everything that we've
00:10learned so far to complete our tasks and that task was to creating that
00:14textualized relationship thing. Alright let's let's do that because we're gonna
00:20be exploring a lot of things that you already saw but into trying together.
00:25Small project so I completed it myself so when you just type here let's say
00:29ben and you tab out then this will be enabled and I could type here maybe mar
00:36for the next item and once I tab out it will be enabled and then I could
00:40actually click on my elements and see them happening. So I want to just
00:45look at the code for a second and you'll see that it's incredibly similar to on
00:48name change and on day change are really almost the same thing but if we
00:52look at it we'll probably notice that they're basically the same thing and
00:57the only difference between them is this line the line where actually the
01:00button analyze and when you think about it is there anything you could do to
01:05make this kind of even more automatic and the answer is yes. To be able to do
01:10that we're gonna need to use something that's called chaining which is kind of
01:13like a name that I invented but I call it chaining and the idea behind it is
01:17basically to create an object we already seen objects we could call this
01:21a linker or a chain and our linker basically its job is going to be to
01:26link between different objects so literally for our case when we have your
01:30our first item would be for example our let's say if we take our property of
01:36the first one that needs to change is the T name right so if I say to my T
01:40name well if I take that T name oopsie what am I doing here I take my T name
01:45I'm gonna copy that and I'm gonna set it to be basically saying hey T name
01:49you're associated with T date and I'm gonna go ahead and say to T date
01:56you're associated with BTN analyze now the idea behind this I'm just gonna set
02:02this as strings because we don't these are not real variables now the idea
02:07behind this is incredibly simple the idea is for us to be able to have a
02:10reference so we don't have to use this and make so we can make it dynamic now
02:15again I'm not gonna talk about how I did this because we already seen it on
02:19the on change that we've created earlier but it really all I need to do
02:23is I want to make sure that this variable is global and it sure is
02:26because it's outside of our on ready function and if we want to make sure that
02:30it's visually that way then you know we have to just make sure that our linker
02:33will be available inside of our properties and we want to do next I'm
02:38gonna kind of like just comment this out and just put a new property here
02:41instead I'm just gonna copy this whole thing again because I want to edit it
02:45and what I want to do is I want to instead of approaching the T date I want
02:49to actually get access to that T date value and to do that what I'm gonna do
02:54is literally and you know it's we're starting from the name itself we want to
03:01approach our basically I'm gonna go back into this we have we have for this log
03:05that gives us that information but what we really want to get is we want to get
03:09the items ID that we just got so if I just save this for a second go back to
03:14my browse or I could just scan through to try to see if I gain access to the
03:17actual ID of the element but also I could just from memory from not memory but
03:23from we learned about properties one of the properties of our element of our
03:28target is the property ID so what I could do is I just could create your
03:32variable call it ID and I could just literally just wrap around the element
03:37that comes back into a jQuery object so we have access to the function prop
03:41and then I could ask for it to return to me the ID now if I do that and I
03:46just output out my ID we should now get that ID value so if I go ahead here and
03:51click on refresh we should now be able to whenever we change something inside of
03:57this element we'll get the actual ID come back beautiful so now that we could
04:02get the ID ID back we could literally just approach this T linker and then
04:07ask for it to that link between our ID to the thing that it's linked to in our
04:11case we're linked to T date and that's the value we want to get back so
04:15if I save this and refresh again that's exactly why I like calling it chaining
04:19because I'm basically chaining items together and if I just change here the
04:44value and click on next we'll see that now we're gonna get the T date beautiful
04:49which is exactly what we hoped to get so back into my application here now I
04:53don't have to refer to the to date directly excuse me I don't have to refer
04:57to the to date directly inside of my function I could literally just
05:00concatenate add that string and say hey add to that the thing you're
05:04linked with inch in the chain of events now that should work so if I save this
05:10and I run it it should literally work but what I'm gonna do now is I'm gonna show
05:14you how I could literally leverage the same function and basically instead of
05:18on change on change it could be on change input and we could literally just
05:23go to on change input and just send that into both functions because now it
05:27should work on both in the exact same way so if I just save this right now
05:31really quickly and you know what because you have already the sample of the
05:34original one I'm just gonna go ahead there and change it completely delete
05:37all the stuff we're not using see how smaller it is if I go ahead English
05:41click on refresh we'll see oh you're not beyond refresh let me just throw the
05:45file right back in so it's completely disabled by default okay so we have your
05:49everything is disabled and I'm just gonna type your Ben gonna tab out oh and
05:54I have your little error on change name is not defined that's true because we
05:58deleted on change name whereas on change on change name is called right here so
06:02let me just comment that out because we're not gonna use it for now let me
06:06just even I'll comment it out yeah we're not gonna just use it for now let's
06:08just focus on this new thing that's going on here so I'm gonna just type
06:14your Ben and I'm gonna tab out and and that's not doing anything let's try to
06:23let's again you know these stuff happen all the time it's completely fine
06:26so let's go back into our editor let's see what's going on so for my T name
06:31which is exactly the item that we're working with I have the event and let me
06:35see also if there's any errors anywhere I'm not seeing any errors okay so
06:39that's a good start so we're not having any errors let me just comment out this
06:42let me just basically the idea is disable everything so you could figure
06:46out what's going on so on change input what I'm gonna do I'm gonna just
06:50directly have your a trace a console log just so I could see that it's
06:54actually being triggered go ahead and save it go back into my browser click on
07:01refresh and again I'm gonna hope that whenever I'm gonna change some copy here
07:04that we're gonna see it you know let me just throw that item just right back in
07:07there in case it somehow got stuck on the old version and I'm just gonna go
07:11ahead and just type something tab out okay here you go that was the file
07:14seemed to have been not cached on an older version which is obviously not what
07:18we wanted so that so we didn't have any error alright so that's good let me
07:22just re-enable that stuff re-enable that stuff run it one more time this time
07:27around I'm just gonna throw the file in instead of clicking on refresh because
07:30it seems that it's remembering things that are happening oh why did I do that
07:35again okay let me save that again let's do this one last time and these are
07:41things that you just have to get used to they're bugs all the time and it's
07:43just part of life so I'm gonna write here Ben tab out and Ben tab out and
07:52here we go this tabbing is working we're gonna type Ben tab out and now this one
07:56is working as well so you see all the steps are now working exactly as we would
08:00hope for it to work and we're not getting any traces because I forgot that
08:03I actually also deleted all the traces so that that's it but I just want to talk
08:07about one more thing I want to show you how could we not even work with
08:10this if because we're only expanding in true or false which is basically a
08:14boolean value we could literally just put here the value that would return a
08:19boolean and we haven't really talked about this much until now but literally
08:24what I could do is I could just take this length and I could and I'm just
08:27gonna kind of like let me just delete all this here and I'm just gonna do a
08:33console log and what I'm gonna do here and I'm just gonna save this
08:37here for a second on the side I'm gonna put here basically the value of
08:41you know let's do this directly in our console so that way you could see it as
08:44oops let's do it directly in the console so you could see what I'm
08:49talking about so if I say three is bigger than one then I'm gonna get a
08:53value saying true if I say three is smaller than one I'm gonna get the
08:56value of false because I'm using the bigger and smaller and that's exactly
09:01what I want you to do right here instead of using false I'm gonna take this
09:03value of length and I'm gonna ask are you greater than zero now if you're
09:09greater than zero then we don't want you to be disabled actually so if
09:15you're we want you to be disabled only if you're equal zero right oh yeah right
09:22so let's say this if if length equals zero which basically means if this if the
09:27length itself equals zero then that would be true so we want it to be
09:39disabled if the length of zero is more than zero then I'll be then I'll be false
09:44basically what I'm doing here is it's making sure that the value which each
09:49time update based on the value that is inside in other words if I save this I go
09:54back into my application and I'm just gonna refresh it completely again and
09:59this time around so notice what's happening so I'm gonna first of all go
10:04ahead and type your Ben tab out and we'll see that now this value is
10:07enabled but if I come right back in there and just delete everything and
10:11tab out you'll see that now it's disabled again all right and that's a
10:15basically what this does basically what it does is because I'm not asking and if
10:19I'm doing this every time no matter what and I'm basically saying if the value
10:23equals zero then make it disabled and every other circumstance make it not
10:28disabled because you're gonna send your false instead of true all right and this
10:32is basically how we basically condensed here everything and literally this
10:38whole thing could have been in one line because I could have taken all this
10:40and just slap it right inside here and all of our function would be one
10:44line instead of all this amount of lines and beyond that if you had for
10:48example a form now and it had 50 different properties and you want
10:51someone to go line by line and not skip anything you literally could create this
10:55logic of a linker and link the elements together one after each other and by
10:59the way you could do this also dynamically once we learn about
11:02something that's called loops but we're not doing loops yet we're not loopy
11:08at loops we're gonna talk about in the next chapter so before we wrap up
11:13this chapter in the next lesson now that everything is working now that the
11:17properties are configured we seen how to work with associated arrays again we're
11:21gonna take a deeper look into arrays and how could we work with them as we
11:25set our analyze function because we want to basically make sure that we're
11:28counting how many people I'm dating or how many people other people are dating
11:32and that's gonna be the whole point of this application so we'll see you in
11:35the next lesson when we wrap up our analyze and actually start analyzing the
11:40values that are coming back

Ready to Level Up Your Skills?

Join thousands of learners on 02GEEK and start your journey to becoming a coding expert today!

Enroll Now for Free!