Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Finds what datetime selections have and have not been filled out
- // Also finds all the datetime selections that was passed in the array
- function find_max_filled_out( check_arrays )
- {
- var filled_out = [];
- var not_filled_out = [];
- var all_selections = [];
- for ( check in check_arrays )
- {
- base = check_arrays[check][0];
- all_selections.push( base );
- i = 1;
- while (i <= check_arrays[check][1])
- {
- select_string = '#' + base + '_' + i.toString() + 'i';
- select = $('#' + base + '_' + i.toString() + 'i');
- select_value = select.val();
- if( select_value != '' & jQuery.inArray( base , filled_out )== -1 )
- {
- filled_out.push( base );
- }
- else if( select_value == '' & jQuery.inArray( base , not_filled_out )== -1
- {
- not_filled_out.push( base );
- }
- else
- {
- break;
- }
- i++;
- }
- }
- return {
- 'filled_out' : filled_out,
- 'not_filled_out' : not_filled_out,
- 'all_selections' : all_selections
- };
- };
- // Adds warnings to all previous datetime selections that haven't been filled out
- $('#order_submit').live('click', function() {
- var number_of_fields_order_order_date = '3'
- var number_of_fields_all_others = '5'
- var check_arrays = [
- ['order_order_date', number_of_fields_order_order_date],
- ['order_csr_received_at', number_of_fields_all_others],
- ['order_so_received_at', number_of_fields_all_others],
- ['order_warehouse_received_at', number_of_fields_all_others],
- ['order_staged_at', number_of_fields_all_others],
- ['order_order_qced_at', number_of_fields_all_others],
- ['order_shipped_at', number_of_fields_all_others],
- ['order_shipped_confirmed_at', number_of_fields_all_others],
- ];
- // Call function to get all selections that have been filled out, have not
- // been filled out, and all the selections we are checking
- var return_values = find_max_filled_out( check_arrays );
- var filled_out = return_values.filled_out;
- var not_filled_out = return_values.not_filled_out;
- var all_selections = return_values.all_selections;
- // Put all the indexs of the selections into in an array
- var index_holder = [];
- // Get all the indexs for the selections that have been filled out
- for ( fill in filled_out )
- {
- //alert( 'x down here: ' + filled_out[ append_to ]);
- var find_index = jQuery.inArray( filled_out[fill], all_selections )
- // if index is not already in the array then add it
- if( find_index != -1 )
- {
- index_holder.push( find_index );
- ///alert('for value: ' + filled_out[ append_to ] + ' the index is: ' + find_
- }
- else
- {
- //alert('not found')
- break;
- }
- }
- // Find the max index for selection that has been filled out, so we can
- // cascade down the selections
- Array.max = function( array ){
- return Math.max.apply( Math, array )
- }
- // the highest index for the selections that have been filled out
- max_index = Array.max(index_holder);
- // Get the selections that have not been filled out and have an index less
- // than the highest index for the selection that has been filled out
- for ( not_filled in not_filled_out )
- {
- check_index = jQuery.inArray( not_filled_out[not_filled], all_selections );
- if ( check_index != -1 & check_index < max_index )
- {
- alert( 'Add warning to ' + '#' + not_filled_out[not_filled] + '_input' );
- $('#' + not_filled_out[not_filled] + '_input').append('<p class="inline-errors">W
- }
- else
- {
- break;
- }
- };
- alert('Warning, there are some fields that should probably be filled out');
- });
Add Comment
Please, Sign In to add comment