Cascading dropdown using MySQL database, Formtastic and Active Admin - ruby-on-rails

I have managed to create a drop-down that is filled from the service model. The service model is managed from a MySQL table. I used this code:
f.input :service, :as => :select #<-- :as not really needed, I know...
I would like to have another select box below the service select that is filled with teams from the team model (teams table in MySQL database) based on what the user selected from the service select.
For example if Service 1 was selected from the service select then the team select would be filled with the teams (Team 1, Team 2) that have the foreign key of service_id = 1 in the teams table in the database. If anyone could help with how to insert the correct associations and Formtastic code to achieve this I would greatly appreciate it.

If you want the contents of one select to change (reduce the number of options) based on the selection made in another select box, this is mostly a client-side programming issue — Formtastic can't modify the DOM once sent to the browser.
You need one piece of JS to watch for changes in the Service select, and another to modify the Team select in some way based on that selection. For this, you have a heap of options here, but it's really not a Formtastic issue, other than perhaps how to render the correct markup for your JS to work.
In the past, I've done all of these at different times:
rendering a separate Team select box for each possible Service selection, then showing/hiding the correct one in the DOM as needed with JS
rendering a data attribute on each option in the Team select noting which Service it support so that the JS can remove or disable options based on the Service selected
I prefer #2, but #1 is probably easier within Formtastic.

Related

Umbraco Extending Tags

I am new to Umbraco CMS, so this question may sound silly. The requirement is to show the tags (based on a specific tag group) to editors in a dropbox, and they could able to choose these tags and save it to the article. What is the best way of achieving this?
The tag property allows free text entry. If you only want editors to select from a predefined list of options you will probably need to do this a different way. You may want to try the dropdown property with the multiple choice option turned on instead. Then you can setup the prevalues (options) ahead of time and your editors can only select from that list.
You could also create a container in the tree for your categories and then allow your admins to select the appropriate items from that list using a multinode tree picker. Here's kind of an example of how you might structure this for a blog:
Blog
Authors
Author
Categories
Category
Posts
Post
Then when an admin adds a new post you would allow them to select the appropriate authors/categories for the post using a multinode tree picker.

rails 5: Dynamic form fields generation

I am new to rails.Currently i am working on a project in which i have three models wholesaler, application_template, and template fields.A wholesaler can create an application_template in which he/she specifies the application fields(by selecting data_type and typing field name)
application_fields form
that would be included in the application_template.
It is working perfectly, but the problem is now i want to store conditional inputs e.g wholesaler wants to specify a field which is required incase if applicant age > 40.
I have searched and go through different documentations but i could not found any solution to store these conditions in db. and then show conditional fields in application form . Can anyone please help me?
i am using pgsql as db

End user can edit the view of a recored in some sort of editor - rails

I'm looking for something like an editor but instead of the user editing just a post or page the user can edit the default template layout or view layout for all pages associated to something.
I'll give an example to get my question across because i really don't know what it would be called.
Say for example you have categories. (people, animals, etc..)
Now imagine there is a category of people, each person in the category has the keys 'height', 'weight' and 'age' and each key has values assigned to them (height: 120 cm, weight: 80 pounds, age: 25)
I want the user to be able to edit the layout of the people page (page template or view that each person is displayed on) and be able to add in the keys they want to be displayed on the page.
So say they add the keys ‘height’ and ‘weight’ it will only display the height and weight on every person page, plus whatever pre set text the user added in the template editor for the people pages to display.
I could probably find a good editor that can be customised and change it to my liking but there might already be gems out there made for this.
My question is, is there a gem for basically letting users set templates for record pages.
Even if there is something out there to change views for objects but the user cant set the keys on it, i'd still like to see it because I might be able to add the key/value functionality to it.
Hopefully you understand what I'm looking for.
UPDATE
Ok so i appears I'm after an editor that works with a template engine like liquid or one thats both an editor and template engine.
If you plan on building from scratch, it sounds like it could be done using rails generate scaffold this allows views/models/controllers to create pages for each of your categories.
Then you can use Associations to create associations between your categories.
You can also make different user roles by making a field called "Role" in your Users relation
Otherwise, there are also open-source software Active Admin to manage content for your categories.
EDIT: After looking around I found a gem you can use to have end-users edit your own views, feel free to check out Liquid.

Select or input

In my app I have a form for creating new trip. Model Trip has field finish_address. For setup the finish_address in I use select in simple form to select address from user's addressbook. But I want to make a better form: if there isn't necessary address, user can add it using input field.
So I need to make form with to types of setup finish_address. How can I make it?
You have 2 basic options.
You can use autocomplete on a text input, populating a dynamic crop-down with know values.
There are several gems available to get you started in this direction, like https://github.com/crowdint/rails3-jquery-autocomplete.
Alternatively, you can add an "other" option to a select input, populated with your known values. When the "other" item is selected, display a previously hidden text input with the same name below the select input. The "lowest" element will take precedence, for what gets sent to the controller.
In the controller, just do a find_or_create_by, using your provided value.
These options both require javascript, but you can eliminate the need for javascript if you make your select a non-db-backed attribute, and manipulate your params accordingly, as they come in to the model. This might help with validations, as well.

Multiple select field in LocomotiveCMS?

I need to set up a field in LocomotiveCMS that is similar to Select but allows multiple selections. Something like in HTML... does LocomotiveCMS allow for that, or will I have to do some ruby coding to get that to work?
Any help would be appreciated, thanks!
Old question but still a thing.
I'm unsure whether your question relates to fields within the Locomotive CMS Back Office or on the front end so I've addressed both below.
Front End
Irrespective of whether or not you're dealing with Locomotive CMS content types, either of the following will allow selection of multiple values on the front end:
Listbox (select element with the multiple attribute)
A series of checkbox inputs with the same value in the name property
Back Office
If you need to allow selection of multiple values within the Back Office, you can do this for content types using the has_many or many_to_many content type relationships.
If you need multiple value selection outside of content types (e.g. in metafields schema) you're unfortunately out of luck.

Resources