Jump to content

The ultimate community for Ruby on Rails developers.


Photo

Viewing JQuery and JS in views

Rails ruby JQuery javascript

  • Please log in to reply
1 reply to this topic

#1 acacia

acacia

    Passenger

  • Members
  • 1 posts

Posted 18 September 2013 - 10:23 PM

Some Jquery scripts are not running in the views while others are running. I want to hide a certain div "#all_lists" and make it appear on click of the "#add_lists" div. The character counter is also not working! All Help is appreciated.



<%= provide(:title, 'Send Message') %> 

<div class="send_sms_form">

  <%= simple_form_for(@message, :html => {:multipart => true}) do |f| %>
      <%= f.error_notification %>

    <div class="form-inputs">
        <%= f.input :from, placeholder: "Max 11 characters" %>
        <%= f.input :to, :input_html => {:value => params[:to], :id => "to"}, placeholder: "Separate Numbers with Comma", hint: "Include atleast one number in this section" %>

        <div id="add_lists"> <span class="button"> Add List </span></div>
        
        <div id="all_lists"> <%= f.collection_check_boxes :lists,  @lists, :id, :name, as: :select %></div>
        <%= f.input :message, :as => :text, :input_html => {:cols => 60, :rows => 7, :onkeypress => "if (this.value.length > 160) { return false; }", id: "compose_message"} %>
        
        <div><span id="char_count">160</span></div>

        <%= f.input :user_id, :as => :hidden, :input_html => {:value => @current_user.id} %>
        <%= f.input :status, :as => :hidden, :input_html => {:value => "Queued"} %>
        <%= f.button :submit, "Send Message" %>
      <% end %>
  
  
    </div>
</div>


$(document).ready(function () {
    $('#to').tagsInput({
//        'autocomplete_url': '/contacts/autocomplete_contact_phone_number',
        'defaultText': 'Add a Number',
        'height': '50px',
        'width': '400px',
        'validator': function (value) {
            console.log(value.length, value);
            if (value.substring(0, 3) == "256" || value.substring(0, 3) == "255" || value.substring(0, 3) == "254") {

                if (value.length >= 11) {
                    return true;
                }

            }
            return false;
        }
    });

    $(".listbox").click(function () {
        var numbers_string = $(this).data("numbers");
        numbers = numbers_string.split(",");
        if ($(this).is(':checked')) {

            for (var i = 0; i < numbers.length; i++) {
                $('#to').addTag(numbers[i]);
            }
        } else {
            for (var i = 0; i < numbers.length; i++) {

//                if ($('#to').tagExist(numbers[i])) {
                    $('#to').removeTag(numbers[i]);
//                }

            }
        }


    });

    $('#messages_table').dataTable() ({
        sPaginationType: "full_numbers"
    });

    $('#compose_message').live('keyup keydown', function(e) {
      var maxLen = 160;
      var left = maxLen - $(this).val().length;
      $('#char_count').html(left);
    });

   

    $('#all_lists').hide();
    $('#add_lists').click( function(event){
        event.stopPropagation();
        $('#add_lists').toggle();
    });
    $(document).click( function(){
        $('#all_lists').hide();
    });


});
[size=4]
[/size]

Edited by acacia, 18 September 2013 - 10:27 PM.


#2 stevieing

stevieing

    Dispatcher

  • Members
  • 40 posts

Posted 19 September 2013 - 10:37 AM

Your best option would be to use a JavaScript debugger unless you have already tried that?

 

For example FireBug for Firefox.

 

 

 

 







Also tagged with one or more of these keywords: Rails, ruby, JQuery, javascript

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users