Variable-length form submissions - ruby-on-rails

I'd like to create a form_for statement which allows the user to select elements one-by-one from a drop down menu (or an auto-complete field). As the user selects each item, they should be displayed in list format at the top of the screen. When the user has finished selecting elements, the form can be submitted and the list of selected elements is sent to the receiving controller action.
Can someone tell me how to implement this?

Maybe Chosen is what you need.
Take a look at:
http://harvesthq.github.com/chosen/

Related

Rails form select from two options with a button - custom form implementation

I have a website where I want users to be able to select what type of user they are during the registration process.
Specifically, the implementation I want is to have two buttons on the signup page, one called "Seller" and one called "Buyer".
The user should be able to select only one button and once clicked, it should stay highlighted (I know this is just jquery so not the issue).
The selection should be stored in a column in my users model called :type.
It seems pretty straightforward, but the "f.select" form method seems to only implement a dropdown menu, so I am wondering how I can achieve this implementation of two buttons.
Since you're already going to use jQuery, you could add a hidden field for type, create 2 links and style them as buttons, and use jQuery to update the value of type when a user clicks one of the "buttons".

Rails-Haml, Table display of checkbox selection

I have a table that displays data for the items selected in the checkbox above, like a[], b[], c[]. Initially, when the page is first loaded, the table display is empty. When checkbox selections are made, the tables displays the data for the selection. Then when I untick all checkboxs and press display, the table display should be empty.
In the controller the variable for checkbox selection is thus>
#selected_brands = params[:brands] || session[:brands] || {}
as you may realize, params[], and session[] are values submitted by form in the view. {} -> when no checkboxes are selected.
Again in controller, I have this
#products = Product.find_all_by_brand(#selected_brands.keys)
The problem I have is, when I have unchecked the boxes, following the previous selections I made, the table displays data from previous session, instead of an empty table. What am I not doing?
You run into a HTML issue bugging lots of people: when you uncheck all checkboxes, nothing is sent to the server, and thus no change is recorded, so the last situation is still recorded.
There are many solutions to this (events, javascript, serverside code), so my advise is to broaden your search to generic html how to handle this situation best.
If you don't like Javascript, and have no problem with too many db-actions, remove all selected brands for the product and reapply the chosen ones when you get this result.

Submitting all items in a select input, even non-selected items?

I have a form, and the user needs to enter a list of email addresses that will receive a periodic report. I thought a good way to do this would be to have a text input, and buttons to add/remove and clear emails in select box. I used javascript to facilitate the buttons adding/removing and clearing the select box and this works fine. One thing I overlooked is that the select box only returns the selected items, however, in this case I want to return all of them.
Is there a way to return all of the items? One idea I had was to add a hidden input and just add the items in there as well.

Blackberry hide fields

I have a dropdown list in which I select how many people are going to a party. When the user changes the value of the dropdown list, I want as many fields as the number selected to appear and hide the rest.
But I don't know how can I hide or delete fields because I don't know their index.
Yes you will need to have the fields you want to hide as a global variables.
You will also need to get the value the user has selected and use that to work out what fields should be removed or added.
One way would be to add all the fields in order to a vector or an array when the screen is initialised. Once the user has selected a value you could iterate through the fields and use the current index of the list and the user selected value to work out if the field should be removed or added.
If you have the field objects, then use Field.getIndex() to find the index of each field within its manager.

ASP.Net MVC - which is the best approach for multi select grouping using JQuery Dialog

This is my scenario
I have an view(page) with list of items, a user could select single or multiple items from this page and click on a "Add to Group" button. Then a modal dialog(JQuery dialog) will be shown, from that he could select group, then press the add button. Which causes the items selected in the parent page is added to that particular group.
So, which is the best way to pass the selected items to the modal pop-up?
Though the query string ? - what happens if the no:of items selected is large, will the url support that much characters
Keep the list in the parent page in a javascript variable and return the selected group from the modal pop-up?
Or is there is any other better option?
Thanks,
Rajeesh
2a. There is no "parent" page; modal dialog is part of the same page as selected items. Therefore on "OK" function from the dialog you can go through the checked items and do whatever you want, including POSTing to the server. It's not clear from your post whether "adding items to the group" happens on the server or client

Resources