Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modal not showing up | Uncaught TypeError: Cannot set property 'texts' of undefined #123

Open
oscarlaf03 opened this issue Jul 20, 2018 · 6 comments

Comments

@oscarlaf03
Copy link

oscarlaf03 commented Jul 20, 2018

Issue

Everything was working fine until the modal for the user to configure their own recurrence on the events stopped to showed up any more. It seems that it the object 'recurring_select' is not getting instantiated but I don't understand why.
What are your thoughts?

Error message

image

My code

app/assests/javascripts/application.js

//= require rails-ujs

//= require jquery
//= require jquery-mobile-rs

//= require recurring_select
//= require flatpickr
//= require flatpickr/l10n/pt
//= require cocoon

//= require_tree .

app/assests/javascripts/functions/recurring_select_translation_portuguese.js

$.fn.recurring_select.texts = {
  locale_iso_code: "pt-BR",
  repeat: "Repetir evento",
  frequency: "Periodicidade",
  daily: "Diariamente",
  weekly: "Semanalmente",
  monthly: "Mensalmente",
  yearly: "Anualmente",
  every: "a cada",
  days: "dia(s)",
  weeks_on: "semana(s) em",
  months: "mesês(s)",
  years: "ano(s)",
  first_day_of_week: 1,
  day_of_month: "Dia do mês",
  day_of_week: "Dia da semana",
  cancel: "Cancelar",
  ok: "Ok",
  summary: "Recorrência",
  days_first_letter: ["Dom", "Seg", "Ter", "Qua", "Qui", "Sex", "Sáb"],
  order: ["1st", "2nd", "3rd", "4th", "5th", "Last"]
}

app/assets/stylesheets/application.scss

// External Gem libraries
@import "recurring_select";

app/views/shared/forms/_form_activity.html.erb

  #[...]
  <%= simple_form_for([tour_store, activity], html: {multipart: true, class: 'form-activity'}) do |f| %>
      <%= f.error_notification %>
  #[...]
  <%= f.select_recurring :recurring, nil, allow_blank: true  %>
  #[...]
  <% end %>

app/models/activity.rb

class Activity < ApplicationRecord
  serialize :recurring, Hash
  #[...]
  def recurring=(value)
    if RecurringSelect.is_valid_rule?(value) && value != 'null'
        super(RecurringSelect.dirty_hash_to_rule(value).to_hash)
    else
        super(nil)
    end
  end

  def rule
    IceCube::Rule.from_hash recurring
  end

  def schedule(start)
    schedule = IceCube::Schedule.new(start)
    schedule.add_recurrence_rule(rule)
    schedule
  end

  def calendar_events(start)
    if recurring.empty?
      [self]
    else
      starts_at = start.beginning_of_month.beginning_of_week
      ends_at = start.end_of_month.end_of_week
      schedule(starts_at).occurrences(ends_at).select{|d| check_event_spots_for(d)== true && d > Date.today }.map do |date|
        Activity.new(id: id, name: name, starts_at: date, max_spots: max_spots)
      end
    end
  end

app/views/layouts/application.html.erb

<!DOCTYPE html>
<html>
  <head>
  #[...]
  </head>
  <body>
  #[...]
        <%= yield %>
        <%= javascript_include_tag 'application' %>
        <%= javascript_pack_tag 'application' %>
      #[...]
  </body>
</html>

Gemfile

#[...]
gem 'recurring_select',  github: "RundownApp/recurring_select"
@xilefff
Copy link

xilefff commented Oct 9, 2018

Same here! Managed to get it working?

@oscarlaf03
Copy link
Author

Yeah in my case it was a messy conflict with the active admin gem, are you using the active admin gem? . It turns out it was a bug because on my asset pipeline I was also calling for the js library of active admin that was conflicting

@xilefff
Copy link

xilefff commented Oct 9, 2018

Hey! Not using active admin :( I've tried removing from the asset pipeline all but recurring_select, but it's still not instantiating

@xilefff
Copy link

xilefff commented Oct 9, 2018

Finally managed to get it working moving the main file in the recurring_select_dialog one, that's the only solution currently working for me. No clues about this strange behaviour. Now the recurring_select object get instantiated correctly. Here's a fork for future readers https://github.com/xilefff/recurring_select :)

In the Gemfile:

gem 'recurring_select', git: 'https://github.com/xilefff/recurring_select.git'

@chiperific
Copy link

@xilefff, do you know if this is still an issue in the GetJobber gem? I see your gem is at 2.0 and theirs is now at 2.1

@xilefff
Copy link

xilefff commented Nov 20, 2018

Hey @chiperific! It seems the bug is still there unfortunately :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants