This question has been flagged
3 Replies
4468 Views

Is there a way to load directly the form view of the first item of a resultset if there is only one item in the results list?
Our users often enters the exactly number/name for a product, order etc. Every time they get a list_view with all the matching results which are in fact just one. Then they have to click this item to get to the form_view.
Is there a way to directly open the form_view for the first matching item if there is only one item in resultlist? Maybe this option can be triggered when executing the search with a SHIFT + ENTER to indicate they want to get to the form directly.

My suggestion is to hook into the search_read result workflow (in JS), check the number of resulted items and modify the url (id, model, view_type) to load the form view if there is only one item.I've tested it manually to change the url from whatever page I am at the moment and it worked so far.

Is there a better way to do so? Are there any things I'm missing our should respect when doing so to avoid unexpected behaviours?

I'm thankful for any advise, thoughts and suggestions! :)

Avatar
Discard
Best Answer

This is exactly what you need (a module with a simple JS file) (tested on V7.0): web_autoswitch_to_form

Avatar
Discard
Author Best Answer

Thanks for the reply. I've implemented for now in the JS code where I check the response items length. Changing the action/response on the server side may be a problem as I figured out when testing. Because when a user toggles back from the form mode to the list mode the same query is send to the server and would response the action to show the form mode again. So the user would stay trapped on the form view.

To manage this I've inspected the JS code if there is any condition to check whether the user searched by himself via the search field or if the search is fired by view toggling. In both cases the same information are send to the server. To modify the search field at this moment also seems to be no option.

So I came along working on the response client side to figure out if I should show the form or not. With a flag that indicates that the user currently switched from form to view mode I can surpress the redirect to the form if there was only one item returned in the search response.

Avatar
Discard
Best Answer

When you return the action on the button click, check in result how many record you are getting using len().

If you are getting exact 1 record then browse the particular models form view which you want to show and pass this in the action..

If  you are getting more than 1 record then browse the particular models list view which you want to show and pass this in the action..


Avatar
Discard