0

Hi I need some more help.

I'm following this tutorial on using client_side_validation: Railcasts: Client Side Validations. It seems straight forwardly easy to use however I can't find how to make it my inline errors show.

Reports Model

Class Report < ActiveRecords::Base
   attr_accessor :producer_selected, producer_id
   belongs_to :producer
   validates :producer_selected, presence => true
   ....

Reports Controller

Class ReportsController < ApplicationController
   def generate_clients
   @report = Report.new(report_params)
   @report.queue_status = "Completed"
   @report.created_by = current_user.id

   respond_to do |format|
     if @report.save

       @producer = Producer.find(params[:report][:producer_id])
       ....

       if @report.report_type == "Clients per Producer"
      requests = Request.from_date_range(params[:report][:from_due_date], params[:report][:to_due_date])
      @records = requests.records(params[:report][:producer_id]) 
    end
    format.html {
      outstrio = StringIO.new
      @report.update_attribute(:date_start, DateTime.now)
      p = render_to_string handlers: [:axlsx], formats: [:xlsx], template: "reports/create_clients"
      outstrio.write(p)
      @report.update_attribute(:date_end, DateTime.now)
      send_data outstrio.string, filename: "#{DateTime.now.to_date} #{@report.report_name}.xlsx"
    }
    format.json { render :show, status: :created, location: @report }
  else
    puts @report.errors.full_messages
    format.html { redirect_to :back, alert: 'Both dates must be filled up.' }
    format.json { render json: @report.errors, status: :unprocessable_entity }
  end
end
end

_clients_form.html.haml

= simple_form_for @report, :validate => true, url:generate_clients_reports_path do |f|
= f.error_notification
.form-inputs
.form-group.col-md-12
  =f.label :from_due_date, :label => "From:", class: "col-md-2 text-right", :style => "margin-top:6px;"
  =f.date_field :from_due_date, :as => :date, class: "range-control col-md-2"

  =f.label :to_due_date, :label => "To:", class: "col-md-2 text-right", :style => "margin-top:6px;"
  =f.date_field :to_due_date, :as => :date, class: "range-control col-md-2"

.form-group.col-md-12
  =f.input :report_type, :as => :select, :collection => @report_types, :wrapper => :field_multi8, :label_html => {:class => "col-md-2 text-right"}, :input_html => {:class => "form-control"}, :label => "Report Type:", :include_hidden => false, :include_blank => false

.form-group.col-md-12
  = f.input :producer_selected, :url => autocomplete_producer_search_string_requests_path, :required => :true, :as => :autocomplete, :wrapper => :field_multi8, :label_html => { :class => "col-md-2 text-right" }, :input_html => { :class => "form-control" }, :id_element => "#report_producer_id", :label => "Producer/Client :", :placeholder => "Find Producer", :update_elements => {}, :autofocus => true
  = f.input_field :producer_id, :as => :hidden

client_side_validations.rb

require 'client_side_validations/simple_form' if defined?(::SimpleForm)
require 'client_side_validations/formtastic' if defined?(::Formtastic)
 <label for="#{instance.send(:tag_id)}" class="message"></label>

 ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
   unless html_tag =~ /^<label/
     %{<div class="field_with_errors">#{html_tag}<label for="#{instance.send(:tag_id)}" class="message">#{instance.error_message.first}</label></div>}.html_safe
   else
     %{<div class="field_with_errors">#{html_tag}</div>}.html_safe
   end
 end
  • Gem is installed already in gemfile
  • Rails 4.2.3

I'm doing all the basic things, but all the basic validations are also not working. After going out-of-focus from the field, no inline validation occurs.

What could be the problem? Help!

EDIT: Also tried this solution but it says that repository is not found.

2
  • 1
    Client side validations are done with html and JavaScript so if they are not working inspect the page Commented Aug 3, 2018 at 8:52
  • @FabrizioBertoglio thanks I'll do that Commented Aug 3, 2018 at 9:04

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.