Skip to content

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

@oscarlaf03

Description

@oscarlaf03

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"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions