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
Related
I want to build a search field that give suggestions based on what the user is typing. Like the wikipedia search bar.
It should only query for the title names (not implementing any complex algo). What is the best way to do this with rails: gem and from scratch?
Use select2 jquery plugin. Its documentation is pretty cool as well. Visit https://select2.github.io/examples.html . Pass your collection to your form select box and call the class of it with select2. It will suggest the user according to the input.
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.
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 implement a helper which contains list of US states. Please check here:
Rails Select Drop Down for States?
Now I have to display the selected US state name on the view file. How can I access that?
As long as it is a drop-down it is working fine.
For example my user selected Maryland ,in the database the value inserted is MD.
Now,I have to display Maryland on the view page.
Please note I have simply created a helper named us_states in ApplicationHelper.
May be:
us_states.select{|v| v[1]=="WA"}.first[0]
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.