Reference: Rails has_many through form with additional attributes
But it is not solution for me... I want to accept only checked elements, without dependency if other attributes are filled.
E.g.: I want to create my menu. There is each food with checkbox and you are able to edit the price in text field (but you don't have to). I want accept all checked foods & save their new price if filled, or old price if not.
Related
As you see in image below after selection of product attribute i want to filter the options based on the selected attribute_id
this is in rails_admin
I'm sorry to say there's no builtin way to do this.
You'll have to clone the existing belongs to field.
Check out the field implementation
https://github.com/sferik/rails_admin/blob/master/lib/rails_admin/config/fields/types/belongs_to_association.rb
And its view
https://github.com/sferik/rails_admin/blob/master/app/views/rails_admin/main/_form_filtering_select.html.haml
You'll find more details on how to create your own custom field here
https://github.com/sferik/rails_admin/wiki/Custom-field
I need to render a <select> with some values.
Those values correspond to a model that the rendered view's model belongs_to - e.g. Foo has_many Bar, I'm rendering Bar, and its form should include Foo's ids and names in the <select>.
That is no problem - right now I'm using simple_form for that.
But in addition to a fixed set of values, the user should be able to insert a new Foo aynchronously (in some popup / whatever), updating the <select> in the browser with the newly-generated id, and the given name.
That is no problem to implement by hand, but is there a Rails feature (like UJS) or plugin (like simple_form) which provides exactly that?
You can try selectize-rails
Examples can be found here. http://brianreavis.github.io/selectize.js/
In My MVC 4 application, I have a Multi Select List Box, where I can select multiple values, I also has an Item New Role as one of the list items, which also refers to a model property NewRole.
So using Jquery whenever the user selections contain New Role, I will provide a text box to the user, which is bind to NewRole from model as given,
#Html.TextBoxFor(m => m.NewRole)
Which also has the following evaluation field.
#Html.ValidationMessageFor(m => m.NewRole)
And I will hide this text-box if the user selected options does not has the Item New Role.
Now the problem is even if I hide the div which contain the Text Box, it will try evaluating the required field validation.
What I require is When User Selects New Role and the User did not enter anything in the provided text Box then validate the required field property.
I know I can write a JQuery to show an alert when the div visible and does't has any value. But I want this default validation should happen on that condition.
is it possible?
One of the trick to avid certain client side validation conditionally ... you can use the IGNORE attribute of the validation ...
jQuery Validate Ignore elements with style
$("#myform").validate({
ignore: ":hidden"
});
If this is not what you are looking ... I will provide more specific information
Yes it is possible with RemoteAttribute. Take a look at this article:
http://msdn.microsoft.com/en-us/library/gg508808(v=vs.98).aspx
Keep in mind that this is NOT client side validation meaning there is an actual server post happening.
Try using the rules add and remove, when new role is selected add new rule which validates the textbox on other selection remove the rule from text box and hide it like you are doing:
http://validation.bassistance.de/rules/
I have a form in rails that allows the user to create a new object (call it a search).
This object has_many excluded_phrases.
What I would like is the ability to display one text box per excluded phrase added.
The form will start out with only a single text box, allowing the user to add one excluded phrase. If they want to add more, there will be button labeled "+" that will dynamically add one more text box, and allow the user to add as many more items as he wants.
On form submit, this should populate the db with the user search, and create all the required phrases that are linked to that user search.
Help?
All inspiration needed is there:
http://railscasts.com/episodes/197-nested-model-form-part-2
This popular rails plugin does exactly what you want.
I've got a list of products in an admin section of my website. I have the product title and then an icon for delete and an icon for set visible/set invisible. I have both icons wrapped in their own form elements so they fire seperate Actions. I now one to add some checkboxes to each line so I can do a bulk delete. Following this:
How to handle checkboxes in ASP.NET MVC forms?
I'd need to wrap the whole list in a form tag to return the checkbox values, but then I have the icons on each row wrapped in form tags. I'm not sure what to do or how to handle this so it all works. How can I maintain the line form tags but still get bulk update functionality?
It's probably going to require some JavaScript. I would create a form outside of the table with a hidden element. When a box is checked, update the hidden element to contain a comma-separated list of all the IDs for rows that have the checkboxes checked (this would be pretty straightforward with jQuery). When that form is submitted, parse the values of the hidden element and delete accordingly.
Another option is to wrap the whole thing in one form and make the names of the delete buttons unique, then check for that when the form is submitted. When doing a bulk delete, you'll have all the checkbox values submitted like normal and you'll know it's a bulk delete based on which button they pressed to submit the form.