Dynamically Changing Simple Form Select on Another Select Change - ruby-on-rails

I have a requirement to modify a select box based on changes made in a previous selection.
In this case I have a simple_form form with a country selection. If a user selects a particular country, a second select field will contain business entity types for the selected country.
For example, in Australia you'd have Sole Trader, Pty Ltd, etc. In the US, you have LLC, S Corp, C Corp, etc.
What I need is to be able to dynamically change the second selection box when the user chooses or changes the selected country.
I'd appreciate your suggestions on how to proceed. I'm using Rails 4 with jquery. Is JavaScript the best/only way to go here, or are their other options for doing this with Rails? Cheers.

Javascript/Jquery is the best way to do this. Bind a change event to your country select list and based on selected country, change the option tags of business entity
Hope this helps!

Related

How to use simple_form with a gem to select state/province and city one a country is selected?

I am looking to a find a solution to select in a form, based on country selected (which works well) one of the states or provinces of the selected country and once the state is selected, one of the cities in that state to be selected further.
I am looking at this gem (since others I found are not a match for Rails 5).
https://github.com/loureirorg/city-state/issues
Or is someone else has a better solution I am looking to use it.

How can I auto-fill Edit fields by using different options of a drop-down list?

am using a VCL form in Delphi, where I have put about 10 edit boxes.
These Edit boxes contain values that are related to specific models of solar panels.
These values are needed in order to calculate the output power of a solar panel.
So far, I am able to type these values in every run with the command:
c0:= StrToFloat(Edit1.Text);
for c0 to c10. But, instead of asking the user to manually type these 10 values in each run, is there any way to let the user select one option (i.e. a model of a solar panel) of a drop down list and these values being filled automatically for them?
Does the combobox do such a thing and if yes, how exactly? I am sorry, I am a very new Delphi user. Any help much appreciated.
Set the combo box Style to csDropDownList.
Populate the combo box Items with appropriate values for the user to select.
Add an OnSelect event handler. This will fire whenever the user selects a new item in the combo box.
Implement the OnSelect event handler by populating the edit controls with appropriate values, based on the value of ItemIndex.
You will need to think a little about the UI. If the user changes the combo box selection, then the edit control values change. But can the user then modify the edit controls? Now the values in the edit controls no longer match the combo box. Is that what you want? I guess that the UI needs a little more polish.

Select fields from multiple records in DBgrid to input in checklistbox?

I created a simple DB with Database desktop (Name, Age, Mail, Place etc.).
One name can include more Places (for example Steve: London, Bukarest, Ukraine).
I want to choose from these places in a new checklistbox or similar component. Is there any way to add these items from the DBGRID into the checklistbox to choose from?
I could not find any tool in the Data controls palette where i can select more items.
dgMultiSelect in dbgrid-->Options allows users to select more than one row.
IIRC it returns bookmarks which are not the easiest thing to work with :(

How to keep track of selections in sequential form

I have what is essentially a form, only the fields depend on the previous selections, and the type of form object aren't always typical form objects.
For example, the first choices are simply in the form of links. It could be a list of teachers, where when you select a teachers name, the classes that teacher teaches is then displayed in a drop-down list. Then once a class is selected, the available dates and time are displayed in a calendar. Once a date/time is selected I need to know all of the selections that were made -- the teacher, the class, and the date and time.
How would you recommend keeping track of these selections? I'm using ajax, and although the form fields are hidden at times, i can still access their values. The one exception is the teacher selection. Since it's just a link, I pass the selected value to a method, but then I've lost the selection. I could store the selection in a hidden field, but is that really the best solution?
Thanks!
I would use a session store on a controller action. Then once it's complete extract all the gathered information.

Why would a SharePoint lookup menu require a double-click to select an item?

I have a SharePoint feature which programatically creates 3 lookups in a custom list, one from each of 3 different lists via extremely similar CAML markup.
The only differences in the CAML are the List, ID, Name, DisplayName and StaticName properties yet one of these lookups looks slightly different (has a slightly more "modern" drop-down arrow) than the other two and this same menu requires I double-click in order to select an item instead of single-clicking as I do with the other lookups.
Might anyone have seen this before and have an idea of what I might look into to make this lookup operate as a single-click menu?
The style of dropdown displayed is usually related to the number of items, although it also renders as a standard select element when viewed in firefox.
For any other field type it would make sense to create a custom field control, but due to code that expects things to be named "Lookup", lookup fields are next to impossible to extend.
The best way to customize a specific field is probably with javascript/jquery. When you click on the dropdown arrow, ShowDropdown (in core.js) is called. This creates a select element with options set from the pipe delimited list in the choices attribute of the textbox.
Add some code to the page so that on load EnsureSelect and FilterChoice or similar are called to create the select element. Set properties on the textbox and select elements so that the textbox as hidden and the select element is a visible dropdown. Have SetCtrlFromOpt called on change rather than on blur/double click so that the control that the server will read and save is properly updated.
The same approach could be used to keep the combo box but add a click event to set the value rather than requiring a double click.
How many items has the source list of every lookup field?
Lookup fields shows a "Combo" when the source list has 10 items (I'm not sure if 10 item is the exact limit). When the source list has more than 10 items the lookup field shows a "ListArea" control that works as you said.
I have exactly the same problem. One difference I have noticed is that the one listbox that requires a double-click is a lookup field, whereas the one that doesn't is a choice field with pre-populated choices. Don't know if that helps.

Resources