#727 open
Bryan Larsen

add name-one-local

Reported by Bryan Larsen | May 23rd, 2010 @ 03:37 AM | in Hobo 1.1

Comments and changes to this ticket

  • Bryan Larsen

    Bryan Larsen April 7th, 2011 @ 07:25 PM

    • Milestone order changed from “0” to “0”

    Current version:

    <!-- see [http://www.mail-archive.com/hobousers@googlegroups.com/msg05953.html](http://www.mail-archive.com/hobousers@googlegroups.com/msg05953.html) for more information on this tag -->
    <def tag="name-one-local" attrs="options, min-chars, nil-value, limit">
    <%
      options ||= begin
        limit ||= 10000
        conditions = ActiveRecord::Associations::BelongsToAssociation.new(this_parent, this_field_reflection).conditions
        this_field_reflection.klass.all(:conditions => conditions, :limit => limit).select {|x| can_view?(x)}
      end
    
      min_chars ||= 0
      value = name(:no_wrapper => true, :if_present => true)
    
    -%>
    
      <div class="name-one-local">
        <ul class="name-one-local-data" style="display:none;">
          <repeat with="&options">
            <li><%= this.to_s %></li>
          </repeat>
        </ul>
        <input type="text" name="#{param_name_for_this}"
               class="local-autocompleter #{type_and_field._?.dasherize} #{css_data :min_chars, min_chars} #{'nil-value' if value==''}"
               value="#{value=='' ? nil_value : value}" merge-attrs/>
        <div class="completions-popup" style="display:none;"></div>
      </div>
    </def>
    
    
    LocalAutocompleteBehavior = Behavior.create({
        initialize : function() {
            this.minChars  = parseInt(Hobo.getClassData(this.element, "min-chars")); 
            var data = this.element.previous(".name-one-local-data").childElements().map(function(el) {return el.innerHTML;});
    
            this.autocompleter = new Autocompleter.Local(this.element, 
                this.element.next('.completions-popup'), 
                data, 
                {minChars: this.minChars, afterUpdateElement: this.afterUpdateElement});
        },
    
        onfocus: function() {
            if(this.element.hasClassName("nil-value")) {
                this.element.value = '';
                this.element.removeClassName("nil-value");
            }
            if(this.minChars==0) { 
                this.autocompleter.activate();
            }
        },
    
        afterUpdateElement: function(input, li) {
            input.fire("rapid:autocomplete-assigned");
        }
            
    });
    

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

People watching this ticket

Pages