In my rails application, i am displaying some records. I am using pagination for records..
i have a javascript function to select all the checkboxes associated with a record..But it selects checkboxes of only current page. I want to have a feature where i can select all the checboxes of current page and then move to next page selec there and then submit all of them together.
I'd say hopping between pages and selecting everything is way too tedious and extremely error prone.
Have your "Check all" function submit something like a yourform[check_all]=true parameter to your controller (via ajax or plain HTTP POST) and have your controller handle the requested action on all relevant records.
Recently I have done the same task as you. I am using table with Ajax pagination, so I can remember all checked positions in array or other object. Then I've added on-click handler to submit button where hidden fields are adding to form to make the same effect as missing checkboxes.
Related
If you believe the title can be edited please feel free to do so.
I have small web app that's used to search for entries in a database. You are given a table of entries, and you can click on one of those entries to expand it down (accordion) to view more details.
I want to add a few buttons to manipulate the entries in different ways, however, I am not sure how to pass information from the button click to a javascript function that I can use to identify and change the data in the database. Pretty much there may be 50 rows in the table, but I want to identify which one the button was pushed in (specifically something that can be used to uniquely identify the row in the database, not in the HTML table).
How/what should I pass to a function when the button is clicked?
I apologize if this is too broad, I have absolutely no idea where to start, any guidance is welcome.
Everything depends on how you submit button click to the server. If you do this with ajax call then the simplest solution will be to add entry id to the request. You can add this id to the table row with data-entry-id="{id_from_table}" and then retrieve it in js. If your buttons are simple links then you can change it to button/input with type submit and wrap it with form which would have hidden field of entry_id.
In a form I have 2 <select multiple> elements. First one is filled with <option> itens in server-side.
I have then developed a JavaScript code to move itens from one to another. That's a basic multiselect feature.
Now I must send second select's values back to server when form is submitted. But it only sends itens that are selected. That's not the behavior I need, I want all existing itens to be sent. Any idea how to implement it, preferably without using Ajax?
I ended up not implementing it. But if I would I'd just try to get all select's values into an array, JSON marshal them and put the string into the input hidden. I'd try to do it in form's submit event.
I have an MVC3 application in Visual Studio 2010.
I have a view with several dropdowns that do javascript calls to populate dropdowns based on the selected value, some of which are disabled initially.
That all works great with the initial state of nothing. If I however pass routevalues to the dropdowns from a redirect to this action, I do get the value set correctly but it's not enabled like it should be on the dropdown for example and when I post the form, the ones that are greyed out are not passed back on the form.
How can I correct this?
Disabled form fields do not get POSTed. Have the value of each dropdown in a separate hidden field so that on from POST it is received on the server.
#Html.HiddenFor(x=>x.SomeID_1)
or
<%:Html.HiddenFor(x=>x.SomeID_1)%>
Another solution is to make them readonly but that way you dont get to edit them in the edit view
I converted a 100% ASP.NET driven form to using nearly all AJAX based architecture except that it doesn't submit the data using AJAX call, yet. It does a full page postback. And because the button submissions are still tied to so much functionality (it's a global button custom control with multiple buttons), I chose not to convert them over to AJAX yet.
Every piece of data submits fine, except for one use-case. It's a dropdown that is dependent from another dropdown. So now, when the value of dropdown 1 changes by the end user, dropdown 2 gets rebuilt from AJAX calls (JavaScript). Note, dropdown 1's options NEVER change in the life of the application. When the form is submitted after that workflow, we lose the value of dropdown 2. Hopefully this is making sense. If dropdown 1 doesn't change, dropdown 2 still has the same options from when the form was built in the code behind, so the value in the viewstate can be found when it's posted.
Right now, I have a hidden field to keep track of that value that was selected and works fine for now, but is a bit clumsy. Before I did this development, both dropdowns had the AutoPostback attribute turned on. That caused the form to get resubmitted without submitting the form, just so the dropdowns could get rebuilt.
Is there a better approach to this problem without making the button perform an AJAX call to submit the data?
Values manipulated in JavaScript can't be maintained on postback, because it won't be accessible on the server side. You can put the selected Value in the Hidden Field and then get it from the Hidden Field.
I was wondering how to go about form validation in rails. Specifically, here is what I'm trying to do:
The form lets the user select an item from a drop down menu, and then enter a number along with it. Using RJS, the record instantly shows up in a table below the form. Resetting the form with AJAX isn't a problem.
The issue is, I don't want the person to be able to select the same item from that drop down menu twice (in 1 day at least). Without using ajax, this isn't a problem (as I have a function for the select statement currently), but now that the page isn't reloading, I need a way to make sure people cant add the same item twice in one day.
That said, is there a way to use some javascript/ajax validation to make sure the same record hasn't been submitted during that day, before a duplicate can be created?
Thanks in advance!
Elliot
With regards to form validations, for your special logic, you'll want to override #validate in your model. See the docs for ActiveRecord::Validations#validate.
Your best bet to "make sure people cant add the same item twice in one day" is to not present the user with options that they can't select. When your controller prepares data for the view have logic that filters out any options that the user shouldn't have (i.e. those they already selected that day). Or present them but disable them as options (so they are grayed out). If the user could select the same option twice in one request you'll want some JS to do client-side validation before a POST to the server.