I need some help to create a jquery script that will handle the car reservation form.
The form have fields such as the “Start date, End date (in datepicker), localization (city) of rent and return the car with the list of direction and the number of days for which the customer borrowed car. There is only one dependency. If the car is rented for less than 4 days the city of borrowing and returning is the same, and if the number of days are greater than 4 days locations of returning car may be different.
The whole form works pretty well, to the point where client chose the city and the number of days is less than 4. The value of first City is “copying” to the second City field (and other values of city are disabled), and that is correct. Under the first city appear the field with directions, but under second city the list of direction not showing (but should, because the city is selected).
When I change the date and the values of total day is greater then 4 and in second field all of city are active and if I select one of them the directions are showing up, and that is ok, but I have to “click” the City. When it is inserting by the script the list of direction are disabled.
Could anyone help me with this?
The workin example: http://jsfiddle.net/amarcinkowski/EbdFY/
You could "force" the change event to execute with
$('#return_car').change()
And the direction input will be shown.
At the first, you duplicate your bindings of change event on #return_car and #get_car. Delete or comment this rows:
$('select#return_car').change(compute);
$('select#get_car').change(compute);
At the second, as Maxime L writes:
if ( parseInt($("#finish_day").val()) < 4 ) {
$('#return_car')
.children('#return_car option[value=' + $('#get_car').val() + ']')
.attr('selected', true)
.siblings().attr('disabled', true);
if ($('#return_car').val()) $('#return_car').change(); // or $('#return_car').trigger('change');
}
Related
Am totaling several form fields where users put in hours of the day. However, some users would like to put an "X" if they were not present that day. So I tried several different if statements to try to get the calculation to recognize "X" as a zero when running the calculation but still show an X in the form field. I went as far as creating a hidden form field and default its value to zero and that is the last thing I tried.
Here is my formula (please keep in mind, I will have to use this for each day of the week but I just was playing around with the first one)
var v1 += getField("mon1_str."+row).value;
if(v1 == "X") event.value = "defaultvalue";
else event.value = "";
The first line of script gets my value no problem. Its the second line and third line where i am not having any luck. It should be noted that no errors are coming up in the console window. "defaultvalue" is the name of my hidden form field to grab a value from.
The + tries to convert the string to a number. But 'x' can't be converted to a number, so it results in NaN.
console.log(+'X');
Try saving the plain value, checking if it's 'X', and then converting it to a number later.
Overview:
I'm not a programmer but I managed to get some serious coding into a Gsheets to track my teams project, so we have multiple-variable dropdown menus and integration with google calendar to track projects development and all that.
Why I'm at stackoverflow:
I kind of lack the knowledge to start the code from the scratch, I usually find spare parts of code through forums on the internet and clue them together and it usually works surprisingly well, but this time I couldn't find much informtation.
What I need:
I have 5 cells, and we can put as below,
Date start - Date end - date code* - number** - Priority***
*script to add the date range to gcalendar
** & *** The number is an array that's based on the word written on the priority cell, for example: If priority is written Weekly them
the number colunm will show 7 on the cell to the left and them it
goes. (monthly = 30 and blablabla...)
So I'd like to know if someone could give a hand with a script that would work (at least in my head) as following:
If I set the priority to weekly, it will show 7 on the number colunm and them, every time the "Date end" has passed, it will automatically add 7 days to the "Date start" and "Date end" again.
That way I could keep the projects on a loop where I'll be able to track them constatly.
Thanks in advance for any insights provided,
ps: I've seen some posts about this on sql, but I have no idea also on how to take advantage of the proposals that were presented there.
Edit:
Spreadsheet picture
eDIT2:
Spreadsheet with a increment colunm
Pertinent to the data set and description, you probably do not need any VBA as the increment could be achieved by adding +1 to the reference pointing to previous cell. For example, assuming cell A1 is formatted as Date, enter in cell B1: =A1+1 , then in cell C1: =B1+1 and so on. The result should be as shown below
A B C
9/1/2017 9/2/2017 9/3/2017
It could be further extended with simple logic allowing do display incremented value only if the previous cell is not empty, like : =IF(A1,A1+1,"")
In your case, it could be cell F1 containing =IF(E1,E1+1,"").
FYI, the underlying value of Date is just an Integer value (Time is represented as decimal part), so the arithmetic operations could be applied.
More generic solution would be based on the Excel DATE() Worksheet formula as shown in sample shown below (adding 1 mo. to the date entered in cell A1):
=DATE(YEAR(A1), MONTH(A1)+1, DAY(A1))
In order to implement additional logic, you may consider using Excel Worksheet IF() statement like for example, cell B1 containing:
=A1+IF(C1="week",7,1)
A B C
9/1/2017 9/8/2017 week
so based on the IF() condition it will add either 7 days if C1 contains the word "week" or 1 day otherwise. It could be further extended with nested IF().
Hope this will help.
I'm implementing a search filter via instantsearch.js with a range slider.
The slider filters a range of years based on the year data column of each item. In this DB tho there are some items with no precise year, but a "supposed" period, like "circa XVIII sec" or "End of 1910s". This means that for these items there is not a single year to filter but rather multiple years.
Let's say for ex. that I wish to filter results in a range of years from 1874 to 1930 and I have an item with "Second half 19th century" in the year field. As you can tell it should result in the match, since any year from 1851 to 1900 is correct for this item.
How should I treat this type of data to be part of this filter range?
How should I structure the data in the year column of this DB?
Should I use some script logic in the algolia javascript search rather than use a special way of structuring the data or indexing?
I was thinking of a logic like:
"If value of item is not just digits, convert it to a range of years.
Then check if the range of these years can match with the filter required in
the slider"
I can't really tell how to do this, and it looks a bit cumbersome and silly to me. I'm pretty sure this is no new issue to face in DB data design, so there has to be a proper way to address it.
I tried searching around but I don't even know how to proper word this thing I'm asking.. if you have suggestions to edit the title please do tell me!
I'm using a MySQL database along with PHP.
With Algolia, you'll need to convert this values to timestamp then you would be able to use numericFilter and add a range slider or numeric refinement list component to your UI.
Also the attribute must be defined as an attributesForFaceting in your index configuration.
https://community.algolia.com/instantsearch.js/documentation/#rangeslider
https://community.algolia.com/instantsearch.js/documentation/#numericrefinementlist
Considering your year as a range, you can either add a beggining and an end attribute to those fields. Example:
EventTimes
id SMALLINT NOT NULL PRIMARY,
yearEnd DATETIME,
yearStart DATETIME
In this case, the end and the start will be equal (I use null ends), when the event is an specific time, and becomes a range when the two fields are filled.
When SELECTing, you can always check for both fields, without a significant loss of speed or accuracy. Then check either for specific time, range of times, or if an event begins, ends, re-begins, re-ends and so on, you can check for different fields within the same table.
So, been looking at search functions in google spreadsheet, and find it difficult to figure out a smooth way to find which column on row one contain a specific value.
To explain a bit more, its a simple allocation spreadsheet, basically who works as what on which project for how long, and as we have a number of different pipelines, I wanted the pipelines separated. So I created a sheet for each, set up the first five collumns so contain all kind of useful info (like resource, project, project role, chargeable, client) then the rest of the collumns represents weeks, so each collumn have the date of the Monday, and all eight sheets have the same setup, so column 6 to 28 contains the date of the following Monday, allowing me to predict resource allocation a total of 22 weeks or thereabouts.
The next step is to create a report (sheet 1) which tells me by resource how busy they are, either as summary or as detailed+summary, and put some colour in if anyone is allocated to many or to few days in a specific week.
I also wanted to view to allow me to specify a date, easy enough, two drop down menus. First is the list of dates row one sheet two, second one is the same list, so the user can in specify 27/01/2014 - 03/04/2014 from the drop down list.
Now comes my issue, I want to retrieve the numerical value of the columns matching the date, so if the start date is in column F I want a variable with 6 in. And end date is in M thats 14.
Anyone have any good suggestions how this can be done?
Tried reading the row and searching it as an array, did not work particularly well
var vcSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Office");
var range = vcSheet.getRange(1,1,1,28);
var dates = range.getValue();
var strCol = dates.indexOf(dtStart);
var stpCol = dates.indexOf('Task');
Browser.msgBox('Found start col on ' + strCol + ' end col on ' + stpCol);
Have you tried .getValues(), as opposed to .getValue()? Maybe something like;
var dates=range.getValues();
for (i in dates[0]) {
if (dates[0][i].indexOf(dtStart)>-1) { some stuff }
}
I am building a scheduling application with Express. I have a calendar view that displays a monthly calendar.
Each day must be completely covered; whether shifts overlap or not, there must be at least one person on a shift at all times.
Given an array of shifts for the day that look like this
{
start: [javascript Date],
end: [javascript Date],
name: "James Bond",
...
}
I want to conditionally add a CSS class to highlight the day if more shifts are needed to fill it.
What is the best way tell if the time between x and y is completely filled?
You need to show what you have tried, but I will give you pseudocode for two basic approaches for this problem.
With either approach, make sure that you are using half-opened intervals for your shifts. This is represented a few different ways:
// interval notation:
[start, end)
// algebraicly
start <= value < end
// javascript and other code
start <= value && end > value
Approach #1
Use Date.getTime() on each date to get a simple numeric representation of each date.
Find a library that implements an Interval Tree.
Map all your shifts onto the tree.
Flatten/merge the tree.
Look for gaps.
Approach #2
Initialize a counter i = 0.
Initialize a dictionary or list of key/value pairs.
For each shift in the list:
If your start date x is in the shift, then increment i.
See if the start time is in the dictionary.
If not, add it with the key being the start datetime and the value being 1.
If it is already in the dictionary, increment the value.
See if the end time is in the dictionary.
If not, add it with the key being the start datetime and the value being -1.
If it is already in the dictionary, decrement the value.
Sort the dictionary by the datetime keys.
Walk the dictionary, starting from x.
i should be starting with the number of people currently working.
Add the value of each dictionary item to your counter i.
If i == 0 then nobody is working. Return false or error.
If you've followed the logic, then i should never be negative. Error if it is.
Continue until your end date y is reached.