On a Rails3 project , I have a requirement where i have to build the form based on the fields & labels that are already saved in the database and i want to save the values in to other tables with other associated records with FORM_FIELD id.
I have a table FORM_FIELDS( name , label ,field_type ) with name of the field , label and its type like text_area ,text_field , integer etc.
I want to build the FORM with fields that will have name , label and type based on the records i choose from the FORM_FIELDS table.
How do i build this form Syntactically correct? , Can anyone please help me out with this design?
Use formtastic gem for doing this on the fly.
Related
I am new to MongoDB.
My application is dynamic form builder that lets users add dynamic fields on the form. None of the field on the form is fix or static. The user can add any number and any type of fields such as Textbox, Textarea, Dropdown, Checkbox, Radiobutton etc fields on the form and save the form.
Can Mongo DB be used for such storage and fetching the data ?
How the data to be stored in Mongo DB and fetched to display the form?
I'm using ASP.NET MVC as a frontend
MongoDB as a backend
Hope for the best answer :)
Thank You!!!
In MongoDB, you don't have a predefined schema for your collection, if you decide that only that document will have an name field, you can. The schema is dynamic so you can add any data you want in your case. It's really useful but you have to be careful after when you query your database for undefined value. Hope this will help you.
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
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.
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.
I'm trying to write a piece of functionality that creates a record from a template in my Rails app, but with some customisations from the user.
The difficulty comes when trying to let the user override a field in an embedded document: the document is duplicated rather than updated.
I start with an object of type, let's say, ExternalLinkGroupTemplate, and it contains a number of ExternalLinks. It's used to create an ExternalLinkGroup which also contains ExternalLinks. The user should be able to edit the link text when it's cloned but not the URL, so the user is presented with a form When it's copied the user should be able to I can create a copy of it with (simplified because some of the code is in different files, remove tests for success etc):
#link_group = ExternalLinkGroup.new
#template.links.each do {|link| #new_link_group.links.push link.dup }
#link_group.update_attributes(params[:link_group])
When the link group is created, it contains twice as many links as the template, and only the second set has the changes. Clearly, Mongoid/ActiveWhatever is creating new items rather than updating existing ones.
I don't want to just pass through all the fields in the parameters without duplicating anything because there's actually some inheritance going on and some of the links will be of different types and have extra fields, and I don't want to code a partial for each of them that just has a bunch of hidden fields. Also, I don't want the user to be able to modify the hidden fields and submit whatever.
I can't reference them by _id because they're not saved yet. I was expecting the array index of template[links_attributes] to be sufficient but it's not.
What do?
Using Rails 3.2.13, MongoDB 2.2.x, Mongoid 3.0.5.