ASP.NET MVC 3 - detect if dirty for multiple checkboxes on multiple pages - asp.net-mvc

I'm using ASP.NET MVC 3.
I have a long list of items and I'd like to display them to the user with a checkbox next to each item representing whether the item is on or off. Because there are many items, the items are display using paging.
When a page is loaded, a checkbox is checked if the item is on. The user can page through the items, check/uncheck the checkboxes.
I want to enable the submit button only when there is a change of the items' states. What is the optimal way to detect if the list of items is in dirty state when the user pages through the list and makes changes.

How you would do this is different depending on if you are doing page refreshes for scrolling or ajax.
If you are just reloading the page with the new page information, then you will need some kind of state to keep track of the previously selected items. This could be done either in Session, or in a temporary table. A temporary table would survive a session reset, and would work in a server farm scenario.
In any event, either your page postsback on checkbox click, or you post on next page (In either case you want to do a post-redirect-get pattern). When the page refreshes, you need to return an indication of whether the collection is dirty or not, and enable the submit button.
Be aware that a user could walk away in mid-selection and come back half an hour later or something. If their login is still valid, and you use session, session may have recycled.
If you're doing Ajax, then you need to keep a running list of changes, so that if the user later unselects them you can disable the submit button again. You would keep this list in a hidden field, and either ajax post each checkbox as it happens to a temporary table, or you could just keep the running total in the hidden and apply the changes when submit is called. Your hidden field would probably contain a list of id's that you have changed (either checked or unchecked). And when the field is empty, disable the button and when it's not, enable it.

Related

What would be the best way to store a list in a GSP page

I currently have a gsp page with pagination and bulk actions based off of checkboxes. I want to store the checked item ids as the user goes to the next page, but to do so I need to store the items the user has checked. I was wondering how I could store that in the GSP page?
Thank you.
I want to store the checked item ids as the user goes to the next
page, but to do so I need to store the items the user has checked. I
was wondering how I could store that in the GSP page?
You could store them in a GSP page simply by defining a variable in the page and assigning it a value of the ids, but that won't solve the problem you are trying to solve because that page will be gone by the time the user navigates to the next page.
Unless you are introducing some client side technology for managing state, a more common thing to do would be to submit the ids to the server and store them in a session or possibly in a database depending on the use case.

Multiple actions on click - ordering issue

When the user clicks on a link to a subpage, I want to store data in sessionStorage from the current page before leaving to the next page. Then when this new page has loaded, I want to apply the sessionStorage data on this page.
What complicates things is that the link is part a collapsing menu system. Which means that this system needs to update (which is also done on click) before the page data is stored.
So essentially, the wanted execution order:
User clicks link
Menu system is updated
Page data is stored
Browser loads the new page
Page data from the previous page loads and applies on the new page
My issue is the order in which everything is executed. I don't understand when the user clicks on the link how to control the order of when the actions are executed.
Thankful for help

Handling the back button while using multi step remote links

I have a 3 step report which loads by clicking a link with the remote: :true option, so it reloads a part of the page instead of refreshing the whole page. I also provide the user with breadcrumbs, so he/she can easily navigate between the steps. However, most users use the browser back button, which of course reloads the whole page. What is the "Rails way" of dealing with this? If the browser back button is clicked the user should see the previous step in the report.
If you need to control the history the user sees, but aren't doing full page reloads on form submit, you should be manipulating the history state via Javascript's history.pushState and friends.
Assuming the responds to the submitted form is some sort of evaluated Javascript, simply include the history state manipulations there.

Mantain page state when coming pressing back button in Rails

Here is my situation:
I have a page with one container which shows all the users, and with another container which will show the users if I have applied any filters.
So, by default I show all the users in the container with id all_users, and if I apply any filters, I hide that container and I do an AJAX call with the ids of my filters and put the contents of the results in a container with id .filtered_users.
When I click on a user though, I go to his page, but when I click the back button I always get all users. I don't get the users that were filtered when I click to that particular user.
How do you do it to mantain the state between those two pages? So that when I click the back button I know where I came from when I clicked into the user.
Thanks
Just track the state through the address-bar in browser, so that you have different addresses for all_users and filtered_users, and thus return to the right one when going back.
It can be manipulated through the history object. See, for example, https://developer.mozilla.org/en-US/docs/DOM/Manipulating_the_browser_history

Parameters through postback

I'm working with Ruby on rails 2.3.4 and I'd like to pass some parameters from one page to another ones the first one is submitted.
For example:
On the first page, I have a form that when it's filled a Preview button can be clicked to check all the info entered before submitting the form. That button redirects to another page with the info entered before, but I don't know how to get it in the second page.
There are two possible solutions:
You can emulate the stepped form filling by creating a record in first form and saving it with status "unverified" or "pending". This way you won't have to deal with hidden form fields in 2nd and 3rd pages. All you'll need to pass is the id of pending record. You'll just need to update record status to "active" once the data is confirmed.
Use client side paginated from (all popular JS frameworks have plugins for this). Hence you will only display different <div>s in single loaded page (something like an interface for a setup wizard).

Resources