Rails/Active Admin/Formtastic - Dropdown cleared on fail validation? - ruby-on-rails-3

When I select a option from a dropdown on the new/edit view and submit the form to the create/update action, if another field within the same form fails the validation process when the view is returned the option selected from the dropdown has been emptied, this isn't a big problem in the new view but definitely in the edit view.
This is the code for the dropdown to be populated using formtastic collection method:
f.input :ethnic_category, :label => "Ethnic Origin", :collection => Hash[EthnicCat.all.map{|b| [b.ethnic_cat_name, b.id]}]
Any help would be greatly appreciated, Thanks....

Related

Asp net mvc 4 Kendo dropdownlist

I have a kendo drop down list it binds on page load.
I have a filter section and I filter one drop down list and I click the submit button and its submitting the page.
When I am clicking the submit button I validates the drop down list whether the user selects the valid input or user types invalid data.
When I clicking the submit button, I save the valid data in hidden field and assigns the value to model property.
After submits the page the selected value(before submits) is selected in dropdownlist.
If now I submit the page once again the drop down list selected index comes as -1.
How to validate this drop down list in the above scenario?
You need to set it's value from model when rendering the page again.
You can easily set by following way using jquery:
$(document).ready(function(){
var dropdownlist = $("#movies").data("kendoDropDownList")
dropdownlist.value($("#value").val());
});

multiple toplevel in vb.net

I have a form "liste of customer" in the right there is a button when u click on it it's show another form named "search" it's let u search by a diff fields this form has a propriety TopLevel=true when user want to search for ex by bank account it's show another form which content the list of accounts this form also has to be on the top I mean has also propriety TopLevel=true but when I execute the code it doesn't work.
Please help me.
NB: TopLevel it s the same propriety as topmost.
You can use the ShowDialog() method instead of Show() e.g.
Search.ShowDialog()
Accounts.ShowDialog()

Hidden model-bound values in view not getting passed to controller when populated manually

I'm using the KendoUI AutoComplete for a number of look-ups on a custom editor template that pop-ups off a grid for new rows and edits. The Kendo AutoComplete does have a DataTextField property and does not DataValueField property like a DropDownList would. So, I found I am able to get the Value of the selected item in the AutoComplete with a little Javascript and iterrogating the "dataItem" object in the select handler. And I put that value into a "SelectedID" field declared with #Html.HiddenFor(model => model.SelectedID) on the select event.
Now, when I do a save from the view and have a break point on my controller action that captures the incoming model, all those ID values where i set the value manually are empty/null/blank. I've checked the DO and have done "console.log" to read out the values of the hidden fields before the post and the values are populated. I've changed the datatypes (strings, guids, etc) and I've changed the Html Helper type as well from a HiddenFor to a EditorFor just to make sure the values are indeed there.
So i think this is a problem when the values of an element that are part of the model are populated in a "manual" fashion. The text of the AutoCompletes comes through if I bind that to a field on the model as well. Any date fields, checkboxes and free-form text fields come through as well. It seems it is just values of model bound fields where I set the values manually that don't make it over the "wire". Any thoughts? Solutions? I know the Selected Value is accessible ... it's just a matter of properly getting it into the "HiddenFor" fields.

Rails date field not removing date when updating

I have a form with a text field for inputting a date:
<%= f.text_field :my_date %>
If I input a date into this field, click submit and then go back to the form again and remove the date value that I've just entered (with no validation applied) the form saves but the original date is still there. I can't get rid of it once I've entered and saved it.
Am I doing something wrong?
It was because it is a virtual attribute and needed to use "" if it thought it was nil

Condtionally hide Edit action for resource in ActiveAdmin

Is there any way to conditionally hide the 'Edit' link per row on #index of a resource?
For example, say you have a User resource. While a User is active, you can edit the User. However, once the User deactivates their account, it should no longer be editable. The User should still show up on the index page with the View link still.
Thanks!
You can make your column instead of default_actions column:
index do
column :actions do |resource|
links = link_to I18n.t('active_admin.view'), resource_path(resource)
if resource.is_active?
links += link_to I18n.t('active_admin.edit'), edit_resource_path(resource)
end
links
end
end