Table-Plus with Select Option

131 views
Skip to first unread message

jhstephenson

unread,
May 1, 2012, 12:22:30 PM5/1/12
to hobo...@googlegroups.com
In another development tool I use, when I have a selection list that exceeds 20 or 30 items I usually create a button on the data entry form that takes me to a screen similar in form to Hobo's Index page. From there I can search for the record I am looking for and then click a button or link to select the record I want. The ID of the selected record is returned to the calling form and the link to the child is established.

It looks to me like that should be possible with something like a Table-Plus based form, but I have no clue how to set that up.

Can someone point me to an example of how something like this might be done?

Thanks,
Jim

kevinpfromnm

unread,
May 1, 2012, 2:45:06 PM5/1/12
to hobo...@googlegroups.com
You're talking about a form input that instead of a plain select, you can filter by name.  You're probably looking for the <name-one /> tag.  You'll need to setup an autocompleter to go along with it.

jhstephenson

unread,
May 1, 2012, 4:17:31 PM5/1/12
to hobo...@googlegroups.com
What I am looking for is something like this:

I have am creating a new part purchased for a customer. It has the following fields:

Name (part description):
Date:
Customer:
Quantity:
etc....

When I get to the customer field, right now it is a drop down box listing all of my customers (or at least as many as are allowed to be displayed). I actually have over 200 possible customers to chose from, which I believe is too many for a drop down box, even if it was allowed.

I am not sure if this can be accomplished by what you are describing or not.

What I would like is the following:

Name (part description):
Date:
Customer: _______________ |Select| (Button or Link)
Quantity:
etc....

When the Select button is clicked I want to bring up a Table view with the folllowing on it:

Search ____________________________

Customer                     Address                       Contact

ABC Customer              Any Address                 Some Contact     |Select| (Button or Link)
.                                                                                                |Select| (Button or Link)
.                                                                                                |Select| (Button or Link)
.                                                                                                |Select| (Button or Link)
XYZ Customer               Their Address               Their Contact       |Select| (Button or Link)

When selected it would return the Customer ID just like it had been chosen from a Drop down list.

I am not sure if that is what you are describing or not.

Does that make sense?

Jim

kevinpfromnm

unread,
May 1, 2012, 4:48:51 PM5/1/12
to hobo...@googlegroups.com
You're not going to get something like that out of the box.  Something like a lightbox or other modal dialog to hold the table.  The table will need to be ajax updated based on filters.  Then you'll need a custom javascript to pass the selection back to the form.

Otherwise you'd need to store/pass along the form information for a standard page load somehow, then repopulate the form when you get back.

Seriously though, give the name-one a try.  It's probably 80-90% towards what you're after functionality wise.

jhstephenson

unread,
May 2, 2012, 6:31:51 PM5/2/12
to hobo...@googlegroups.com
I  think I must be missing something on how name-one works.

Below is what I have from my application.dryml for my product form:


<extend tag="form" for="Product">
    <old-form merge>
        <field-list: fields="category, customer, department, vendor, name, serial_number, date_ordered, date_received, date_invoiced,
        vendor_invoice, scc_invoice, quantity, dollar_amount, warranty_years, warranty_days, item, comments">
           
            <name-label:>Part Description</name-label:>
           
            <category-tag:><name-one/></category-tag:>
            <customer-tag:><name-one/></customer-tag:>
            <vendor-tag:><name-one/></vendor-tag:>
           
        </field-list:>
    </old-form>
</extend>

When I run it, I don't get anything different. I must have missed something on how to use name-one.

Jim

kevinpfromnm

unread,
May 2, 2012, 6:42:52 PM5/2/12
to hobo...@googlegroups.com
The parameter is field-name-view: not -tag.  I usually put in some plain text before adding a tag just to make sure I got the parameter right.

jhstephenson

unread,
May 2, 2012, 6:46:52 PM5/2/12
to hobo...@googlegroups.com
I must really be missing something because all that does is bring up an edit field. There is no link to the table at all.

Ignacio Huerta

unread,
May 3, 2012, 10:13:10 AM5/3/12
to hobo...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

It looks like an "edit field", because name-one is indeed an input
field where you can type. The trick is: you start typing the name of a
client, and then you are given a list to select from, just like when
you are start typing in Google and Google suggests some possible words.

If it doesn't work you can monitor the Ajax calls in several ways. For
example, you can look at the log or use Firebug's network tab.

Regards,
Ignacio

El 03/05/12 00:46, jhstephenson escribi�:
> -- You received this message because you are subscribed to the
> Google Groups "Hobo Users" group. To view this discussion on the
> web visit
> https://groups.google.com/d/msg/hobousers/-/_uq48N2YymoJ. To post
> to this group, send email to hobo...@googlegroups.com. To
> unsubscribe from this group, send email to
> hobousers+...@googlegroups.com. For more options, visit
> this group at http://groups.google.com/group/hobousers?hl=en.

- --
Ignacio Huerta Arteche
http://www.ihuerta.net
Tel�fono: 0034 645 70 77 35
Email realizado con software libre
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk+iknYACgkQBPlUJ6RHaOQpIACfYISIdMZlsBCe6aeC2sf1WBo7
DmEAoNBAphAG2VlXq/1U69DfDeb3fKkY
=F8to
-----END PGP SIGNATURE-----

jhstephenson

unread,
May 3, 2012, 9:22:08 PM5/3/12
to hobo...@googlegroups.com
Ok. Here is what the log shows when I try do it on just my Category field:

Started GET "/categories/complete_name?query=Computer" for 127.0.0.1 at 2012-05-03 19:18:24 -0600
  [1m [36mSQL (2.0ms) [0m  [1mSHOW TABLES [0m
  [1m [35mSQL (1.0ms) [0m  SHOW TABLES
  [1m [36mSQL (2.0ms) [0m  [1mSHOW TABLES [0m
  [1m [35mSQL (1.0ms) [0m  SHOW TABLES
  [1m [36mSQL (1.0ms) [0m  [1mSHOW TABLES [0m
  [1m [35mSQL (2.0ms) [0m  SHOW TABLES
  [1m [36mSQL (2.0ms) [0m  [1mSHOW TABLES [0m
  Processing by CategoriesController#show as JS
  Parameters: {"query"=>"Computer", "id"=>"complete_name"}
  [1m [35mSQL (1.0ms) [0m  SELECT COUNT(*) AS count_id FROM `users`
  [1m [36mUser Load (1.0ms) [0m  [1mSELECT `users`.* FROM `users` WHERE (`users`.`id` = 1) LIMIT 1 [0m
  [1m [35mCategory Load (0.0ms) [0m  SELECT `categories`.* FROM `categories` WHERE (`categories`.`id` = 0) LIMIT 1
Completed   in 20ms

ActiveRecord::RecordNotFound (Couldn't find Category with ID=complete_name):
 

Rendered C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.0.1/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.0ms)
Rendered C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.0.1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (3.0ms)
Rendered C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.0.1/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (16.0ms)

I assume the key entry here is the one indicating that ActiveRecord could not fine the Category with ID=complete_name.
Should there be a method in the Category controller called complete_name?

Jim

On Tuesday, May 1, 2012 10:22:30 AM UTC-6, jhstephenson wrote:

Matt Jones

unread,
May 4, 2012, 7:56:46 AM5/4/12
to hobo...@googlegroups.com

On May 3, 2012, at 9:22 PM, jhstephenson wrote:

> Ok. Here is what the log shows when I try do it on just my Category field:
>
> Started GET "/categories/complete_name?query=Computer" for 127.0.0.1 at 2012-05-03 19:18:24 -0600
> [1m [36mSQL (2.0ms) [0m [1mSHOW TABLES [0m
> [1m [35mSQL (1.0ms) [0m SHOW TABLES
> [1m [36mSQL (2.0ms) [0m [1mSHOW TABLES [0m
> [1m [35mSQL (1.0ms) [0m SHOW TABLES
> [1m [36mSQL (1.0ms) [0m [1mSHOW TABLES [0m
> [1m [35mSQL (2.0ms) [0m SHOW TABLES
> [1m [36mSQL (2.0ms) [0m [1mSHOW TABLES [0m
> Processing by CategoriesController#show as JS
> Parameters: {"query"=>"Computer", "id"=>"complete_name"}
> [1m [35mSQL (1.0ms) [0m SELECT COUNT(*) AS count_id FROM `users`
> [1m [36mUser Load (1.0ms) [0m [1mSELECT `users`.* FROM `users` WHERE (`users`.`id` = 1) LIMIT 1 [0m
> [1m [35mCategory Load (0.0ms) [0m SELECT `categories`.* FROM `categories` WHERE (`categories`.`id` = 0) LIMIT 1
> Completed in 20ms
>
> ActiveRecord::RecordNotFound (Couldn't find Category with ID=complete_name):
>
>
> Rendered C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.0.1/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.0ms)
> Rendered C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.0.1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (3.0ms)
> Rendered C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.0.1/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (16.0ms)
>
> I assume the key entry here is the one indicating that ActiveRecord could not fine the Category with ID=complete_name.
> Should there be a method in the Category controller called complete_name?

Yep. The quickest way to get one is with the autocomplete method:

http://cookbook.hobocentral.net/manual/controllers#autocompleters

--Matt Jones

jhstephenson

unread,
May 4, 2012, 3:23:30 PM5/4/12
to hobo...@googlegroups.com
Thanks,

That will give me what I want. On thing I notice is that the search result brings up anything found with the matching characters, not just something that starts with what I type. I actually like that better than what I planned, but if I wanted to limit it to just the starting characters of a name field, is there a way to filter it that way?

Jim

kevinpfromnm

unread,
May 4, 2012, 4:30:31 PM5/4/12
to hobo...@googlegroups.com
The autocompleter provides a default finder which you could override to only return results starting with your match.  You might want to do that for performance reasons as matching text anywhere in a string is much more expensive than matching the beginning (of an indexed column).

kevinpfromnm

unread,
May 4, 2012, 4:33:21 PM5/4/12
to hobo...@googlegroups.com
Oh, there's a parameter in autocompleter to specify a different query_scope from default now (as opposed to using a finder).

jhstephenson

unread,
May 4, 2012, 5:47:21 PM5/4/12
to hobo...@googlegroups.com
Thanks,

I just have to learn more about scopes now. I wish there were more examples for things like this.

Jim

kevinpfromnm

unread,
May 4, 2012, 10:05:46 PM5/4/12
to hobo...@googlegroups.com
Scopes are a rails thing so there's more than just hobo's docs.
Reply all
Reply to author
Forward
0 new messages