Site.
This code is not optimized nor is it the best method. If you have any ideas to improve anything, let me know.
Please visit the site to get an idea of the data.
I have used Dan G. Switzer, II’s calculation plugin [adding .sum() .max() .min() .avg()]
The validation requirement i’d like to have is to make sure nothing conflicts with that user’s already determined range. Also, that there are no gaps in the range.
For example give
Brian 40 50 1200
Brian 50 70 1200
I dont want to the user to be able to set the first 50 to 39 because 39 would be smaller than 40. I dont want them to let 50 be set to anything higher than 50 because it would overlap the next range.
Any good ideas? perhaps actually running through all the values and then making a real range and then on BLur have it check to make sure no range is actually overlapped or gapped.
Each unique input is defined as id=NAME, so if I wanted to reference all the inputs of Brian, I could use $("input[id='Brian']").each() or if I wanted to reference all the START inputs of Brian, I can use $("input[id='Brian'][name='start[]'").each()
Edit:
One thing to note is that the page is PHP, and PHP is ran to populate the inputs via a CSV file. It will always start with correct data, and PHP can be used to help create ranges.
because of this I was thinking of just disabling the START field, because it will always populate the next range. However, I will be adding the ability to delete rules, so that can get messy if they are limited in what they can do.
One of the problems I see is that the Name fields is editable. If the field is changed, all the overlapping has to be recalculated. Not only is that is a performance issue, it is also a usability problem: what if one wants to change a name and the script, seeing discrepancies, forbids it?
A solution would be to change the table to one resembling the diagram below:
The [ Add Employee ] button would ask for a name and add a cell in the first column, and a line in the next three: with a default Start value of 0. The user can then enter data on the next fields, and can [ Add Rules ] as wanted. A good restriction could be to lock the values of the Start column and set them to the End value of the previous line.
Then adding a comparison function to check if the End value is lower than the Start value is trivial to implement.
Deleting a rule could simply follow the same procedure as for adding a line: the line below the one deleted (if any) would set its Start value as the now previous line’s End.
The real difficulty would be to insert lines at arbitrary points. I’m not going to think about that one, though.
EDIT:
If a rewrite is out of the question, then just disabling the start should be enough. However, IMHO I would rather (re)write something with no caveats than spend time later on numerous bugs and feature requests.