Fixed various issues with the new appointment form

This commit is contained in:
ricky committed 2026-08-06 20:36:35 -04:00
1 parent 10fdfba032
commit d17f58fb62
6 files changed
+74 -7

No files matched your search

@@ -16,6 +16,15 @@ class CustomerAppointmentsController < ApplicationController
helper :projects
def customer_options
customer = Customer.find_by(id: params[:customer_id])
render json: {
vehicles: customer&.vehicles&.map { |v| { id: v.id, name: v.name } } || [],
estimates: customer&.estimates&.map { |e| { id: e.id, name: e.name } } || []
}
end
def index
if params[:project_id]
@project = Project.find(params[:project_id])
@@ -33,6 +42,7 @@ class CustomerAppointmentsController < ApplicationController
@appointment = CustomerAppointment.new
@appointment.project = @project
@appointment.start_date = (params[:start_date].to_date + 9.hours) if params[:start_date].present?
@appointment.end_date = @appointment.start_date + 1.hour if @appointment.start_date.present?
end
def create
@@ -6,17 +6,17 @@
<p>
<%= f.text_field :customer, label: :label_customer, class: "customer-name", autocomplete: "off", data: { autocomplete_url: "/customers/autocomplete" } %>
<%= f.hidden_field :customer_id, id: "customer_id", onchange: "this.form.requestSubmit()" %>
<%= f.hidden_field :customer_id, id: "customer_id" %>
</p>
<p>
<%= f.label :vehicle_id, l(:label_vehicle) %>
<%= f.collection_select :vehicle_id, @appointment.customer&.vehicles || [], :id, :name, { include_blank: true }, { label: false } %>
<%= f.collection_select :vehicle_id, @appointment.customer&.vehicles || [], :id, :name, { include_blank: true }, { label: false, id: "appointment_vehicle_id" } %>
</p>
<p>
<%= f.label :estimate_id, l(:label_estimate) %>
<%= f.collection_select :estimate_id, @appointment.customer&.estimates || [], :id, :name, { include_blank: true }, { label: false } %>
<%= f.collection_select :estimate_id, @appointment.customer&.estimates || [], :id, :name, { include_blank: true }, { label: false, id: "appointment_estimate_id" } %>
</p>
<p>
@@ -24,7 +24,7 @@
<%= f.collection_select :user_id, User.active.sorted, :id, :name, { include_blank: true }, { label: false } %>
</p>
<p><%= f.date_field :start_date, size: 10 %></p>
<p><%= f.datetime_local_field :start_date %></p>
<p><%= f.date_field :end_date, size: 10 %></p>
<p><%= f.number_field :estimated_hours, step: 0.1, size: 6 %></p>