recordselect not updating list as I type.

35 views
Skip to first unread message

coalex

unread,
Dec 30, 2014, 7:27:29 PM12/30/14
to actives...@googlegroups.com
Hey Serg,
I wanted to have an autocomplete field on a few forms where the drop downs are getting too long.
So...
I got recordselect working, but the list of options do not dynamically update as I type in the form field.
There are no obvious errors in the console.
Any ideas, Thank you!!

Started GET "/locationtypes/browse?search=" for 127.0.0.1 at 2014-12-30 17:22:05 -0700
Processing by LocationtypesController#browse as */*
  Parameters: {"search"=>""}
   (1.0ms)  SELECT COUNT(*) FROM "locationtypes"
  Rendered .../gems/recordselect-d5ed9fff0efc/app/views/record_select/_search.html.erb (1.0ms)
  Locationtype Load (2.0ms)  SELECT "locationtypes".* FROM "locationtypes" ORDER BY name LIMIT 12 OFFSET 0
  Rendered .../gems/recordselect-d5ed9fff0efc/app/views/record_select/_list.html.erb (5.0ms)
  Rendered .../gems/recordselect-d5ed9fff0efc/app/views/record_select/_browse.html.erb (17.0ms)
Completed 200 OK in 83.0ms (Views: 73.0ms | ActiveRecord: 5.0ms)

Rails 3.2.17
active_scaffold (3.3.3)
recordselect 3.4.3 from git://github.com/scambra/recordselect.git (at master)
jquery-rails 3.0.4
jquery-ui-rails 4.1.0


Sergio Cambra

unread,
Dec 31, 2014, 2:45:52 AM12/31/14
to actives...@googlegroups.com, coalex

Do you get requests to browse action on server or network tab of web inspector?

coalex

unread,
Dec 31, 2014, 12:29:33 PM12/31/14
to actives...@googlegroups.com, alexande...@gmail.com
I do get a request to the browse action when I click on the form field, but only once, it is not kept alive as I type.
If I click off the field and then back on,  it will send a request with what ever I typed before.

Maybe a jquery issue? I'm poking on it today.

Sergio Cambra

unread,
Jan 2, 2015, 4:49:32 AM1/2/15
to actives...@googlegroups.com, coalex

delayedObserver code was updated on ActiveScaffold and RecordSelect. You are using a new recordselect version (with updated code) with an old ActiveScaffold version (with old code). You can downgrade recordselect to 3.3.0, upgrade ActiveScaffold, or try to set this code above activescaffold:

 

if (typeof(jQuery.fn.delayedObserver) === 'undefined') {

(function($){

$.extend($.fn, {

delayedObserver: function(callback, delay, options){

return this.each(function(){

var el = $(this);

var op = options || {};

el.data('oldval', el.val())

.data('delay', delay || 0.5)

.data('condition', op.condition || function() { return ($(this).data('oldval') == $(this).val()); })

.data('callback', callback)

[(op.event||'keyup')](function(){

if (el.data('condition').apply(el)) { return; }

else {

if (el.data('timer')) { clearTimeout(el.data('timer')); }

el.data('timer', setTimeout(function(){

var callback = el.data('callback')

if (callback) callback.apply(el);

}, el.data('delay') * 1000));

el.data('oldval', el.val());

}

});

});

}

});

})(jQuery);

};

 

Copy this code to a file and require it above activescaffold on your assets manifest.

Alexander Mendoza

unread,
Jan 2, 2015, 2:57:43 PM1/2/15
to Sergio Cambra, actives...@googlegroups.com
Thank you for your insight Sergio!
I went with downgrading the recordselect. This is working perfect now.

#Gemfile
gem 'recordselect', :git => 'git://github.com/scambra/recordselect.git', :tag =>'v3.3.0'

Message has been deleted

mvargo

unread,
Mar 23, 2015, 3:47:09 PM3/23/15
to actives...@googlegroups.com
I am having similar erratic behavior with the record_select feature.  The issue is that I can see the calls to the browse function on the controllers and I see the return with the javascript to call RecordSelect.render_page('record-select-admin_zen_products...
but the UI does not show up.  I don't see an error in the javascript console either.

It does not happen all the time.  The site I'm working on was up for a week and being used every day and then started to fail.  Feels like a client side timing issue.

I upgraded to latest jQuery and did a bundle update so have new active scaffold.

Any ideas?

Gemfile:

gem 'rails', '3.2.21'
gem 'mysql2'
gem 'active_scaffold'
...
gem 'recordselect'
...
gem 'jquery-rails'
gem 'jquery-ui-rails'
# To support jquery-tools, but not included in admin ux
gem 'jquery-migrate-rails'


Gemfile.lock extracts

    active_scaffold (3.4.18.1)
      rails (>= 3.2.18, < 5)

    recordselect (3.4.4)
      rails (>= 3.1.3)

    jquery-rails (3.1.2)
      railties (>= 3.0, < 5.0)
      thor (>= 0.14, < 2.0)
    jquery-ui-rails (5.0.3)
      railties (>= 3.2.16)

admin.js.erb

//= require jquery
//= require jquery-ui
//= require jquery_ujs
//= require jquery.ui.nestedSortable
//= require sortable_tree/initializer
//= require active_scaffold
//= require record_select

Sergio Cambra

unread,
Mar 24, 2015, 4:56:01 AM3/24/15
to actives...@googlegroups.com, mvargo

Do you get any JS error on web inspector console?

mvargo

unread,
Mar 24, 2015, 1:20:03 PM3/24/15
to actives...@googlegroups.com, mfv...@gmail.com
No JS errors.  The code executes successfully.  The call to RecordSelect.render_page... does not create an error.  I copied the line from the Network request and pasted it in the console and it executes.  I opened the gem and found this

RecordSelect.render_page = function(record_select_id, page) {
  jQuery('#' + record_select_id + ' ol').first().replaceWith(page);
};

I did the jquery selector on the console and it is finding the element.  I think the problem has already occurred so the dom modification is fine, the css was not tweaked earlier so the drop down is not visible.

That happens when the input gets focus and it calls 

browse?search=

I see the partial (not javascript but html fragment) of the form with the <ol> beneath it from the network return but that does not display on the screen in the error case.  I'm not sure what is catching that browse?search= return but that is where the error happens.

One other point is the same controller allows update on existing records.  Those work.  It's only the create with a blank input that creates the problem.

This is the top of that fragment

<div class="record-select" id="record-select-admin_zen_products">
  <form accept-charset="UTF-8" action="/admin/zen_products/browse?page=1&amp;search=&amp;update=1" data-remote="true" id="record-select-admin_zen_products-search" method="get"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /></div>  <input autocomplete="off" class="text-input" id="search" name="search" type="text" value="" />
  <input class="search_submit" name="commit" type="submit" value="search" />
</form>

  <ol>
  <li class="found">3345 zen product found</li>
  <li class="record odd" id="rs5596">
    WIR047 (0.0) -  14g FINE Silver round, dead soft wire - 1 ft 
  ...
lots more

Sergio Cambra

unread,
Mar 25, 2015, 3:53:26 AM3/25/15
to actives...@googlegroups.com, mvargo

Can you check css properties for that record-select div with inspector? Is there any display: none property?

mvargo

unread,
Mar 25, 2015, 6:47:26 PM3/25/15
to actives...@googlegroups.com, mfv...@gmail.com
I got it! The bottom position of the fragment is not correct.  It's a really large value and so the drop down is there but it's off the screen below.  I modified that bottom attribute in inspector and the box showed up.  I will look into how the record_select gem decides where to put the box.  Must be some kind of javascript code there that maybe gets the location before the page is settled or something...

Details;

So I have cases where I'm using record_select on the same model (zen_product).  The first one works every time and the other fails every time.

The form element on the javascript partial is identical for both cases and looks like this:

<li class="form-element  record_select ">
    <dl><dt><label for="record_zen_product_">Zen product</label></dt><dd><input autocomplete="off" class="zen_product-input text-input recordselect" id="record_zen_product_" name="" onblur="this.focused=false" onfocus="this.focused=true" type="text"><input type="hidden" name="record[zen_product]" value=""><script type="text/javascript">
//<![CDATA[
new RecordSelect.Single("record_zen_product_", "/admin/zen_products/browse", {});
//]]>
</script>


</dd></dl>
  </li>

When I click on the input in the success case, it inserts a chunk into the dom at the bottom and then positions it and it shows up.  When I click on the failure case, it still inserts the div in the dom but it does not show up.  Here is the top chunk of that stuff (i will leave out the <ol> with the choices in them.  (same data in both cases)

Failure case:
  <div class="record-select-container record-select-handler record-select-autocomplete" style="display: block; left: 219px; bottom: 1219px;"><div class="record-select" id="record-select-admin_zen_products">
  <form accept-charset="UTF-8" action="/admin/zen_products/browse?page=1&amp;search=&amp;update=1" data-remote="true" id="record-select-admin_zen_products-search" method="get"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓"></div>  <input autocomplete="off" class="text-input" id="search" name="search" type="text" value="">
  <input class="search_submit" name="commit" type="submit" value="search">
</form>

  <ol>
  <li class="found">3369 zen product found</li>
  <li class="record odd" id="rs5596">
    WIR047 (6.0) -  14g FINE Silver round, dead soft wire - 1 ft 
  </li>

Success case:
  <div class="record-select-container record-select-handler record-select-autocomplete" style="display: block; left: 219px; top: 911px;"><div class="record-select" id="record-select-admin_zen_products">
  <form accept-charset="UTF-8" action="/admin/zen_products/browse?page=1&amp;search=&amp;update=1" data-remote="true" id="record-select-admin_zen_products-search" method="get"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓"></div>  <input autocomplete="off" class="text-input" id="search" name="search" type="text" value="">
  <input class="search_submit" name="commit" type="submit" value="search">
</form>
  <ol>
  <li class="found">3369 zen product found</li>
  <li class="record odd" id="rs5596">
    WIR047 (6.0) -  14g FINE Silver round, dead soft wire - 1 ft 
  </li>
...

mvargo

unread,
Mar 25, 2015, 7:04:14 PM3/25/15
to actives...@googlegroups.com, mfv...@gmail.com
A bit more info.  I find that if I use a tall monitor and scroll the page so that there is plenty of room for the autocomplete to fit below the input element, the recordselect div positions correctly.  It's only when I don't have room  below to fit the div it puts in the bottom value that is too large.

looking at the code I see in the show: function on the Recordselect
(jquery/record_select.js in the gem line 214 is show:)

      if (position == 'top') this.container.css('top', top);
      else this.container.css('bottom', document_height - offset.top);

So it seems to me the calculation of the bottom height is not working.  Document_height is  found above there as

document_height = jQuery(document).height();

Maybe that is the entire document height but you want the window height?  I'm not really an expert at client side javascript...

Sergio Cambra

unread,
Mar 26, 2015, 4:22:22 AM3/26/15
to actives...@googlegroups.com

El Miércoles, 25 de marzo de 2015 16:04:14 mvargo escribió:

> A bit more info. I find that if I use a tall monitor and scroll the page

> so that there is plenty of room for the autocomplete to fit below the input

> element, the recordselect div positions correctly. It's only when I don't

> have room below to fit the div it puts in the bottom value that is too

> large.

>

> looking at the code I see in the show: function on the Recordselect

> (jquery/record_select.js in the gem line 214 is show:)

>

> if (position == 'top') this.container.css('top', top);

> else this.container.css('bottom', document_height - offset.top);

>

> So it seems to me the calculation of the bottom height is not working.

> Document_height is found above there as

>

> document_height = jQuery(document).height();

>

> Maybe that is the entire document height but you want the window height?

> I'm not really an expert at client side javascript...

 

How is input positioned? static? fixed? If record select has an absolute position, we want document height, because bottom 0 is at document bottom. However if input has fixed position, then we need to use window height.

 

I would need a test page so I can see why is not positioned right to fix it.

Sergio Cambra

unread,
Mar 26, 2015, 8:34:29 AM3/26/15
to actives...@googlegroups.com

I see the issue. body or html needs to be positioned relative. In other case recordselect position absolute works like position fixed, i.e. relative to window instead of document, so bottom: 0px is window bottom.

 

I usually have body { position: relative; } in my css, however I have added some code to fix position record select above input when body or html doesn't have position relative.

 

You can update record select or add body { position: relative; } to your css.

Mike Vargo

unread,
Mar 26, 2015, 1:04:58 PM3/26/15
to actives...@googlegroups.com
That worked! Thank you for your help figuring this out.  I justed added position: relative; to my body block and voila!  I'm sure I'll pick up your fix on the next bundle update.

Mike

--
You received this message because you are subscribed to a topic in the Google Groups "ActiveScaffold : Ruby on Rails Gem" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/activescaffold/kZBG-B3E3kY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to activescaffol...@googlegroups.com.
To post to this group, send email to actives...@googlegroups.com.
Visit this group at http://groups.google.com/group/activescaffold.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages