Checkbox reveal which items are selected on page - ruby-on-rails

on my page a user can select multiple items.
I use a checkbox and iterate over all the items of a user.
Now I want to show the user the total price of all the items he selected on that page.
So to say the total price of the shopping cart.
How can I access the ids of my items on the same page that the user clicks on them? I know that in the controller I can access them by
Item.find(params[:items])
Thanks a lot in advance :)

You'll need to do this via Javascript.
One way is to store the id in the data tags of your html element (checkbox in this case)
Then you can get this value in your Javascript callback as
element.getAttribute('data-type');
or if you are using jQuery
$(this).data("id")
Now you will need to access the value of the item (individual price for the item with the selected id) as well in Javascript. You can do this by either storing the mapping of id to price in a js variable
let prices = <%= #items.select(:id, :price).to_json %>;
or alternatively, you can just store the price in a data-attribute of each checkbox, and use this value to update the total selected price.

Related

ViewModel not keeping data on postback

I have a ListBox implemented as below.
#if (Model.SelectListVendorBranchSearched != null )
{
#Html.ListBoxFor(model => model.SelectedVendorBranchLeft, Model.SelectListVendorBranchSearched, new {#class="listbox", #size ="10" })
}
But when the form is posted back the viewModel object does not have the original Data Source that the list was bound to. But it has the selected items posted back.
Is that the right behavior?
Let me try to explain what I am trying to achive.
I am trying to implement the following in ASP.NET MVC.
I have a search functionality that populates a list box say List box A. Now I need to select some items in the List Box A and move the items to another List Box say List Box B. Then do another search that refreshes the List Box A with fresh results. Then again select some more items in the List Box A and append to the items already in List Box B. In the end get the items in the List Box B and save it to DB. How can I do this without any JavaScript?

How to retain values of dropdown with selected values in MVC?

The scenario is - There are two view in my mvc application. One is Index and other is for adding payment details. in index form I fetch details of a perticular client in that I have cascading dropdown one for selecting type and one for according to type select client in another dropdown, both are coming from DB's and on d same view I have an ActionLink for going on Payments view "for adding the payment details for the same client that is been selected on Index views second dropdown (first is for Type)".
My problem is that when I am going on Payments view and clicking back button of browser to go back on my index page it is clearing the second dropdown. and all other data is safe on the form. So can you please help me to avoid this so that all the data of my Index view should retain throughout the execution.
This also in case when I add Payment for that client and click submit it should redirect on the Index view with retaining all its previous data. that we have fetched on Index page.
with a message box Payment Added successfully.
You can save the current selected values of dropdown1 and dropdown2 into one of the followings:
URL
Session
Cookie
Then in the Index page you always check to read those values if they are existed to setup the dropdowns in the first request. Then do update those values again whenever user selects to update the dropdowns.

Edit multiple rows in Table Struts2

I am displaying a list of data returned from database to JSP.
Now, this list has fields that are editable. And user can select more than 1 row to edit.
My requirement is to display the list, override the list(which has dropdown and checkbox fields that can be overridden by user) and then all of it to be saved to database.
I used displayTag to display the data, but now User editing few fields and populating that table to Action class part I am not able to get.
Can you give some suggestions?
May be other than displaytag also?

Magento Collection load for sales order with custom fields

I am new to magento. I have added two text fileds(custom options) for products in magento admin panel.
When the customer purchasing products these two text fields are required. I need to load the collection for sales order to get this two fields.
Customer fields namely like:
1) domain name 2) activation code
Can any one give me guidance? How to get this text fields from magento sales order?
thanks
Below collection will get your products custom fields from sales order
I have tried my self and got the final result.
Note : These products custom fields values entered by the customer in the product details page.
$order = Mage::getModel('sales/order');
$orderItems = $order->getItemsCollection();
$orderItems->addFieldToFilter('product_options',array('like'=>'%'.$domain_name.'%'));
$data = $orderItems->getData();

Ruby on Rails HABTM Multiple Dropdowns with AJAX

I have a typical HABTM relationship between members (actual members of our organization, not all have online accounts) and users (online accounts). I have an edit users page for site administrators where multiple members can be assigned to users.
There are too many members to reasonably use checkboxes or a multi-select dropdown. I have decided to use dropdowns that are added by clicking an "Add Member" button that uses an AJAX function to add a dropdown.
Here's what I have working:
I can add dropdowns and pick any member. On save, the relationships are established.
I can edit that user and add more members, remove members, and change members in the dropdown.
The final piece I am struggling with is having my remove link (next to each member drop down) remove a drop down for a new user. The reason being that the action behind the remove link relies on the id of the div that contains the dropdown. When editing a user, this id is generated based on the selected member. For a new user, I do not know the selected member in the dropdown, so I can't assign it an id that I can know about when the remove link is clicked.
Are dropdowns the way to go? Are there any good tutorials or examples of what I am describing out there? Should I perhaps update the div ID in an onchange event in the dropdown?
I have found that the best way to do this is to use the object_id of member to create a unique div id. My Javascript function is then able to use this to remove the div.

Resources