I'm creating Rails movie ticket booking application. The issue I'm having is to make sure that the seat chosen by user is next to each other.
Say, a user is choosing seat with value checkbox
[2]
out of [1,2,3,4,5]
, if maximum ticket he purchased is two
, then he can only choose 1,2 or 2,3.
[x][2][3][x][x]
or
[1][2][x][x][x]
Here is snippet i'm doing to make sure user does not choose more than amount they booked.
$('input[type=checkbox]').change(function(e){
if ($('input[type=checkbox]:checked').length > <%= @total_adult.to_i + @total_children.to_i %>) {
$(this).prop('checked', false)
alert("Only " + <%= @total_adult.to_i + @total_children.to_i %> + " is allowed per your request.");
}
});
My checkbox looks something like this:
<input type="checkbox" class="check_box" name="booking_confirmation[]" id="2_3" value="10553" />
<label for="2_3">
B3
</label>
<input type="checkbox" class="check_box" name="booking_confirmation[]" id="2_4" value="10554" />
<label for="2_3">
B3
</label>
...
Where 10553, which is the ID of the seats that increment by 1. I'm thinking difference between the first and the last seat should not be more than the ticket he purchased, which was two. But then, I can't think how to solve this.
Aucun commentaire:
Enregistrer un commentaire