WEBVTT 00:05.740 --> 00:10.570 In this video we're going to write code to submit the editorship for. 00:10.930 --> 00:21.280 So we will write the javascript code inside the selection of the model because we need to write code 00:21.700 --> 00:23.590 for this specific trip. 00:23.920 --> 00:24.920 OK. 00:25.780 --> 00:26.050 So 00:30.850 --> 00:35.540 first of all we will need to select the form and then use the same method 00:38.620 --> 00:41.310 to select the form using its ID. 00:49.570 --> 00:56.990 Ok then use the method. 00:57.410 --> 01:00.110 So this method will take a function. 01:00.230 --> 01:01.580 Ok I'm going to give it 01:06.040 --> 01:07.880 performance events. 01:08.060 --> 01:10.560 I was going to be using the event objects. 01:10.610 --> 01:15.800 So first of all we can to prevent the devote the full submission of the form as we did before with the 01:15.800 --> 01:22.590 other forms using the prevents default method of the event objects. 01:23.030 --> 01:31.900 Then we going to store all the user inputs inside a data variable. 01:31.910 --> 01:42.450 I've already done this with the creates trip form so I'm going to select the form and just use the keyword 01:42.630 --> 01:53.740 this and use the serialize array function or method. 01:54.090 --> 01:59.050 I said we have already done something very similar for creating a form 02:11.370 --> 02:12.060 and write that 02:15.790 --> 02:20.230 OK and just make our code tell me the I'm going to define these variables right at the beginning of 02:20.230 --> 02:21.540 the file. 02:32.190 --> 02:37.810 Well writes right now to edit the trade. 02:38.140 --> 02:43.270 We need the user inputs but we need also the ID of the trip. 02:43.620 --> 02:55.240 OK so we're going to push into the data array using the push method the ID of the trip. 02:58.910 --> 03:04.960 So we're going to send the elements with a name and a value. 03:05.760 --> 03:11.550 OK so the name is going to be trip ID. 03:13.980 --> 03:16.060 You can choose any name you like. 03:16.170 --> 03:21.430 It just needs to be the same one that we're going to be using in the file later on. 03:21.700 --> 03:40.190 OK the value of the trip ID can be retrieved from the Invoca variable by getting the data to be as trip 03:40.190 --> 03:45.510 ID. 03:45.520 --> 03:53.000 All right so once we do that then everything else is exactly the same as the code that we have written 03:53.080 --> 03:55.560 for creating a tree. 03:55.570 --> 04:02.440 So if you go back to the code we've written for creating a trip we use a function gets Tripti Pasic 04:02.440 --> 04:04.840 organist's to get the coordinates of the departure. 04:05.020 --> 04:07.430 OK so we can use exactly the same thing. 04:07.600 --> 04:12.610 So we're just going to rename this function to eddied strip instead of 04:16.870 --> 04:19.150 going to create this function now. 04:28.160 --> 04:32.600 So it's going to be very similar to that function. 04:32.820 --> 04:35.030 So we're going to copy the code from this function 04:37.970 --> 04:47.910 to save time and changed the name of the function to get a trip departure coordinates. 04:47.910 --> 04:55.000 OK so what's going to change here inside the function is that the ID of the departure is departure to 04:57.910 --> 04:58.630 also 05:05.990 --> 05:10.790 we will change the second function which will guess the destination coordinates. 05:10.830 --> 05:13.710 So instead of a trip we're going to have a trip 05:20.320 --> 05:21.070 OK. 05:22.880 --> 05:29.590 Then we're going to define this function gets it a trip destination coordinates and for that we can 05:29.590 --> 05:31.690 just copy that one 05:42.090 --> 05:46.920 in just name its gets it a trip. 05:52.050 --> 06:00.870 So it will change the ID of the destination to destination to. 06:01.290 --> 06:08.130 And when we submit the request we're going to use another function that's going to call it's a day trip 06:08.130 --> 06:08.860 instead of three 06:14.950 --> 06:20.040 and these are misfunction is going to be also very similar to the old one. 06:20.080 --> 06:26.060 It's really just copy the code from there creates the new function 06:32.540 --> 06:36.970 call it some it's a trip instead of it. 06:38.290 --> 06:38.560 OK. 06:38.560 --> 06:47.440 So the rail here is going to be updates trips those BHB that's where we're going to send the school 06:52.080 --> 06:53.540 OK. 06:53.710 --> 06:53.890 And 06:57.440 --> 07:01.330 the error is going to change. 07:01.330 --> 07:07.980 So the idea of the area of all the edits form is a trip message 07:20.690 --> 07:22.150 the ID of the model 07:26.090 --> 07:26.930 of modal 07:30.350 --> 07:31.620 and the idea of the four 07:35.780 --> 07:36.970 is editorship phone 07:43.530 --> 07:44.750 that again the message 07:47.860 --> 07:55.700 the editrix message OK sort of save. 07:56.350 --> 07:57.590 So everything looks fine. 07:57.600 --> 08:00.420 So she's going to check something here. 08:17.940 --> 08:20.170 OK. 08:20.260 --> 08:26.140 So when we submit the form we'll soon need to empty the error message if there are any errors there. 08:26.320 --> 08:28.270 So she's going to select 08:31.600 --> 08:33.770 the error message and it's empty. 08:34.120 --> 08:34.670 OK. 08:34.840 --> 08:37.120 So now let's save this. 08:37.390 --> 08:40.900 Now let's move to the HP file. 08:41.020 --> 08:47.260 So that's the file that's going to use to update the trip details. 08:47.260 --> 08:50.670 So it's going to be very similar to the Tripps file. 08:50.680 --> 08:54.870 The only thing that's going to change is the query. 08:55.290 --> 08:55.640 OK. 08:55.750 --> 09:00.250 Everything else is going to be the same because when you are filling this form it's like you're creating 09:00.250 --> 09:02.190 a new trip. 09:02.230 --> 09:07.140 The only difference is that the trip is already there and we're going to use the ID of the trip to update 09:07.140 --> 09:07.630 it. 09:07.970 --> 09:08.460 OK. 09:08.470 --> 09:19.770 So to save time I'm going to copy the code from the ship's file and copy it to the update chips file. 09:20.500 --> 09:32.430 Now the only extra inputs that we've got with the trip form is the trip ID OK which we retrieved from 09:32.550 --> 09:33.820 the Edie's person. 09:33.970 --> 09:39.300 So let's define a variable for that's call trip ID 09:43.750 --> 09:45.050 so you going to get hit by 09:47.750 --> 09:56.530 taking the elements of key trip ID in sight of those three. 09:56.910 --> 09:57.440 OK. 10:02.340 --> 10:05.980 And that's the elements we're looking at. 10:06.330 --> 10:10.090 OK. 10:10.130 --> 10:20.360 All right so now when we come to the query instead of inserting a new record we're going to be updating 10:20.450 --> 10:27.290 a record and the condition is a much of the trip ID. 10:27.700 --> 10:28.250 OK. 10:28.580 --> 10:33.040 So instead of insert we're going to update the table 10:37.070 --> 10:38.580 and say it's 10:48.140 --> 10:50.240 each of these elements. 10:50.390 --> 10:54.210 Ok to the value of those we find in the form. 10:54.770 --> 10:54.980 OK. 10:54.980 --> 11:00.420 So let's start with the departure. 11:00.630 --> 11:02.320 So again two sets. 11:02.400 --> 11:03.230 Dep. 11:06.660 --> 11:07.120 2 11:12.920 --> 11:15.920 the value of the punch is made by the user. 11:20.000 --> 11:22.710 And then departure longitude 11:29.840 --> 11:34.620 to the departure received value. 11:36.770 --> 11:37.390 And so on. 11:37.460 --> 11:39.320 So just to save time 11:42.890 --> 11:50.030 I'm going to pause the video right here and what I'm going to do is I'm going to be setting each of 11:50.180 --> 11:53.320 these fields. 11:53.410 --> 11:54.150 OK. 11:54.600 --> 11:59.810 Or call them names to the Volga the corresponding value that's you find there. 12:00.100 --> 12:01.370 OK. 12:01.390 --> 12:02.870 So when a pause right now. 12:03.160 --> 12:08.790 All right so now I've set all the values to all the column names to the proper values. 12:08.980 --> 12:12.710 Now the condition is going to be where because a. 12:12.760 --> 12:41.440 Much of the trip ID. 12:41.660 --> 12:48.470 And also we're going to miss this operation to only one record and we know anyway that is only one record 12:48.470 --> 12:53.120 so just to be cautious we usually limits one right then. 12:53.310 --> 12:56.430 I just say it's only one record to be updated. 12:56.840 --> 12:57.400 OK. 12:57.530 --> 13:00.390 So we're done with the query. 13:00.410 --> 13:05.050 We're going to do exactly the same thing with the one of trip query. 13:05.060 --> 13:13.330 So all I'm going to be doing is setting the column names to the right values. 13:13.330 --> 13:13.760 OK. 13:13.860 --> 13:18.650 So again I'm going to pause the video and do this just to save you time. 13:19.530 --> 13:20.060 All right. 13:20.280 --> 13:22.720 So now you got both our queries ready. 13:22.740 --> 13:29.440 So once we run the query and we check we're going to check if the query is successful if it's not then 13:29.440 --> 13:30.810 we're going to show an error message. 13:31.050 --> 13:35.970 So instead of saying the chip could not be added to the database we're going to say the trip could not 13:35.970 --> 13:41.280 be updated. 13:41.280 --> 13:45.820 All right so before testing the code we're going to make a quick change inside the jobs because while 13:46.190 --> 13:47.400 we've got a 13:50.260 --> 13:53.410 going on there that's not supposed to be that. 13:53.440 --> 13:59.660 So now let's save try our code. 13:59.850 --> 14:00.670 So if the 14:03.630 --> 14:09.210 change anything inside the strip then click on the Edie's present 14:15.850 --> 14:16.820 so you can see those. 14:17.080 --> 14:19.600 It didn't recognize any of the inputs. 14:19.600 --> 14:28.200 And the reason why is because the names of those inputs are different from the Create trip process. 14:28.210 --> 14:34.420 So when we get the inputs we will need to change all these to the new names. 14:34.420 --> 14:39.860 So I departure to this nation to and so on 14:49.290 --> 14:50.160 that's when the same 14:53.770 --> 14:54.420 OK. 14:54.590 --> 14:57.490 So it's save and refresh 15:00.520 --> 15:00.770 OK. 15:00.770 --> 15:01.790 So this change this 15:06.800 --> 15:11.960 way you can see this chip has been updated so let's try something else. 15:15.800 --> 15:16.910 Okay perfect. 15:18.620 --> 15:19.580 All right. 15:20.210 --> 15:24.370 So our it is functionality is now complete before moving on. 15:24.380 --> 15:27.200 I'm going to delete this person because we don't need it's 15:37.550 --> 15:49.100 gay and also you will notice that if you try the autocomplete feature right there isn't going to work 15:51.920 --> 15:52.830 again. 15:53.030 --> 16:00.490 That's because we didn't build an auto completes very well for these two fields. 16:00.650 --> 16:07.960 So you got to go back to the map those days file OK so it's opening again. 16:12.240 --> 16:31.040 So we're just going to a couple of other inputs so input 3 or destination to inputs for all departure 16:31.050 --> 16:34.670 2 and another one for designation 2. 16:34.960 --> 16:45.780 And then we're going to use those inputs to build two other autocomplete objects to complete three and 16:45.810 --> 16:46.670 four. 16:47.130 --> 16:51.830 And then we're looking at input number three and input number four. 16:52.020 --> 16:56.220 So let's save and try our code 17:05.810 --> 17:06.720 OK. 17:06.870 --> 17:07.730 I need networks 17:12.850 --> 17:14.260 right. 17:14.330 --> 17:14.590 All right. 17:14.590 --> 17:18.980 So in the next video we're going to write code to delete a trip.