The following code is working correctly apart from the case of CurrentMaxValue is 10 the options will only give 10 regardless of input value
one other problem is that it will allow option of 10 despite CurrentMaxValue being lower than 10 (when second option box is filled with a different value the first then defaults to the remaining quantity)
Code works correctly whilst using fiddle however it does not work when copied into application. any suggestions ?
cart item model
class CreateCartItems < ActiveRecord::Migration[5.2]
def change
create_table :cart_items do |t|
t.references :cart, index: true, foreign_key: true
t.references :train_class, index: true, foreign_key: true
t.references :passenger, index: true, foreign_key: true
t.integer :passenger_qty
t.integer :male
t.integer :female
t.decimal :unit_price
t.decimal :total_price
t.string :outbound
t.timestamps
end
end
view
<div class="female-male-options">
<div class="female-box">
<%= f.label (t "reservations.female_passengers"), {:class => 'form-container-item-label'} %>
<%= f.select(:female, @travelers, {selected: @travelers_select}, { id: 'female'}) %>
</div>
<div class="male-box">
<%= f.label (t "reservations.male_passengers"), {:class => 'form-container-item-label'} %>
<%= f.select(:male, @travelers, {selected: @travelers_select}, { id: 'male'}) %>
</div>
</div>
its controller
class ReservationsController < ApplicationController
def show
...
@travelers = [0,1,2,3,4,5,6,7,8,9,10]
@travelers_select = params[:travelers]
end
end
problem solved with adding
> parseInt()
to MaxValue.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.