0

This is for a school project and I am stuck. I am trying to implement a calendar which will popup the dialog window upon the calendar cell click. Please note that below code is an attempt of a total rails newbie who know 0 to nothing about it (Thanks to my college professor). I have crammed it all into one partial which in theory should work just fine... here s the code

    <div id="calendar"></div>
<div id="createEventModal" class="modal hide" tabindex="-1" role="dialog" aria-labelledby="myModalLabel1" aria-hidden="false">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">x</button>
        <h3 id="myModalLabel1">Create Appointment</h3>
    </div>
    <div class="modal-body">
    <form id="createAppointmentForm" class="form-horizontal">
        <div class="control-group">
            <label class="control-label" for="inputPatient">Patient:</label>
            <div class="controls">
                <input type="text" name="patientName" id="patientName" tyle="margin: 0 auto;" data-provide="typeahead" data-items="4" data-source="[&quot;Value 1&quot;,&quot;Value 2&quot;,&quot;Value 3&quot;]">
                  <input type="hidden" id="apptStartTime"/>
                  <input type="hidden" id="apptEndTime"/>
                  <input type="hidden" id="apptAllDay" />
            </div>
        </div>
        <div class="control-group">
            <label class="control-label" for="when">When:</label>
            <div class="controls controls-row" id="when" style="margin-top:5px;">
            </div>
        </div>
    </form>
    </div>
    <div class="modal-footer">
        <button class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button>
        <button type="submit" class="btn btn-primary" id="submitButton">Save</button>
    </div>
</div>

  <script>
    $(document).ready(function() {

      var calendar = $('#calendar').fullCalendar({
      defaultView: 'agendaWeek',
      editable: true,
        selectable: true,
      //header and other values
      select: function(start, end, allDay) {
          endtime = $.fullCalendar.formatDate(end,'h:mm tt');
          starttime = $.fullCalendar.formatDate(start,'ddd, MMM d, h:mm tt');
          var mywhen = starttime + ' - ' + endtime;
          $('#createEventModal #apptStartTime').val(start);
          $('#createEventModal #apptEndTime').val(end);
          $('#createEventModal #apptAllDay').val(allDay);
          $('#createEventModal #when').text(mywhen);
          $('#createEventModal').modal('show');
       }
    });

  $('#submitButton').on('click', function(e){
    // We don't want this to act as a link so cancel the link action
    e.preventDefault();

    doSubmit();
  });

  function doSubmit(){
    $("#createEventModal").modal('hide');
    console.log($('#apptStartTime').val());
    console.log($('#apptEndTime').val());
    console.log($('#apptAllDay').val());
    alert("form submitted");

    $("#calendar").fullCalendar('renderEvent',
        {
            title: $('#patientName').val(),
            start: new Date($('#apptStartTime').val()),
            end: new Date($('#apptEndTime').val()),
            allDay: ($('#apptAllDay').val() == "true"),
        },
        true);
   }
});
</script>

When I run my app on localhost and click on the cell my screen just dimms as if its gonna show the modal but I do not see the modal. I have referred to numerous examples on internet and older training projects I have done all to no avail(I do have bootsrap and jquery along with all necessary files included... I even tried using script src links but they just break all javascript on my page period). Here is the link to js fiddle example: http://jsfiddle.net/mccannf/AzmJv/16/

Thank you for help!

  • Are there any errors in the dev tools console? – akatakritos Apr 15 '14 at 14:10
  • Do you have: gem 'jquery-turbolinks', in your gemfile? And if you put: alert("jquery works!") as your first line after the $('document').ready... line, does it fire? – steel Apr 15 '14 at 14:12
  • And have you seen this question/answer: http://stackoverflow.com/questions/8529420/how-to-show-twitter-bootstrap-modal-via-js-request-in-rails?rq=1 – steel Apr 15 '14 at 14:14
  • I have turbolinks gem in my Gemfile(Is there difference between?). I get 0 errors in console. Alert fires off as soon as I refresh the page. Also yes, I have looked at the solution link yesterday but that didnt work I got same result. If needed I can add more code. Funny thing was that I have taken some other example code off SO and it worked just fine... but it was far from what I was trying to do. – pirate694 Apr 15 '14 at 14:30

0 Answers0