If there is no mistake:
React-Router's <Link/> component can carry over data (state) when the user doesn't leave the current tab or you force the user to open new tab on left click using target="_blank". Otherwise the state you send with it is lost because we'll have a new empty history stack.
localStorage can be used to share state between tabs but it's problematic in scenarios where i just want to store the data for only the regarding tab user is expected to navigate.
e.g. I want to set a state using the state/data I've stored for that specific tab and doesn't want to store it anymore/ forget about it. In this case, synchronization problems may occur when the user actually creates multiple tabs using the same <Link/> component but doesn't navigate to all of them. How?
Say, I've removed the state item from the storage when the component is unmounted in one of the tabs user is already navigated and, later on the user is navigated to another tab expecting the item in the storage to set the state. (The component in this tab will try to set state with non-existent data / will crash.)
I could hold the state till the window's onunload event is fired at best, but the problem still exists because localStorage is shared across all of the tabs and removing an item affects all the tabs like i've mentioned. ~ I have to remove the items somehow, can't rely on storage of 2MB to 10MB forever. I tried to find other solutions like clearing it once in a while on user logout/login but that would force the user to take those actions again, once in a while.
So I want to be able to store selected the state/data on sessionStorage of the newly instantiated tab and it gets cleared for me when that tab is closed and I don't have to deal with the regarding problems.
The problem could be defined with simpler words as:
I want to send a piece of data from one tab to another with empty history stack in the scope of only that tab.
Because I don't need it anywhere else.
I can do things like setState using that data, remove that data etc. and the other tabs launched in need of that data don't get affected.
I've searched through the other questions but there are not detailed answers covering this scenario or I couldn't come across with a best practice for this kind of stuff using ReactJS. Sorry If this is a duplicate.
i have 2 forms in React JS and i want to carry the data of the first form to the second form by clicking the next button .After that i want to check if the data is true then load the data of another form. If yes click the save button (Submit button) to save the data of the first and second form at same time onSubmit
Save the data from the first form into state, then pass the state as props into the second form component. You can check if the data exists when the second component mounts with 'componentDidMount' or the useEffect Hook.
See this article on building multi-step forms with React.
I have multiple forms and I want to know which one of them was visited.
visited or touched don't help because they're about fields, and forcing the user to click one of the fields just for that isn't what I want nor is intuitive.
So is there another way to know if a form was visited?
I'm on redux-form 6.8.0.
Let's say we want to create a new Task. We have 2 categories of information we want to collect from the user for creating a new Task: general params, action params.
To make it easily separated we are separating between them with tabs. so each gets its own react component, both stored in different react-tabs tabs.
In the parent component I have a save button and I want that at any given time, the user could click it to send the entire state from both the tabs' state to the server.
While I could forward event handlers from the parent to the children (as suggested by other questions on this topic)... doing it for each of the 20 controls (dropdowns, textfields, date time pickers) in each of them requires a lot of boilerplate code and seems unreasonable.
I'm looking for a best practice for this situation. Thanks!
I am trying to create a content type (say Meter). Each Meter consists of a "Meter Reading". This meter reading content contains three fields, say title, date range and usage. I have a Panel page where I display all the Meter Readings related to a parent Meter. I have displayed the Meter Readings in a tabular format.
I want the user to be able to add new Meter Readings without going to the default Meter Readings creation page. Rather than the default form kind of page, the user should be able to enter the data in the table view provided and it should be automatically saved into the project itself.
So, I want the functionality to be like:-
Display all the meter readings with two links, i.e., Edit and Delete,
When the user clicks on Edit link, the meter reading row should become editable and the user should be able to make the changes inline in the same table,
In the footer there should be a link for adding a new meter reading and when the user clicks on it, a new blank row should be added dynamically to the table and the user should be able to make a new entry into it.
Is there a module in Drupal 7 for doing so?? I have already tried out several modules for this such as SlickGrid, jQGrid and jEditable
Any help would be great. Thanks in advance.
Am afraid am not aware about a module that does all that out of the box. But in case you carry on with custom coding you can have a look at the following:
Edit and Delete options per row in views
Use Views Megarow. For working example you can have a look at how its used in commerce backoffice. Please note that you need to write the form structure ( FORM api ) for the quick edit form in a custom module. The Views Megarow takes care of ajax populating the edit form, its submission in client side, and refreshing the original row after the response from server.
When the user clicks on Edit link, the meter reading row should become editable and the user should be able to make the changes inline
in the same table.
Views Megarow doesn't support inline editing. But another module as suggested by #nmc does it. Its editablefields. But it doesn't have any edit/delete button. You click on the text directly ( provided user has appropriate permission to edit the field data ) in view.
In case you are going to use editablefields, then you would have to add another delete button in view, which one confirmation would redirect to the page that triggered delete action.
Since delete button would redirect to a default confirmation page, you may want to code a custom delete action which may override this.
In the footer there should be a link for adding a new meter reading and when the user clicks on it, a new blank row should be
added dynamically to the table and the user should be able to make a
new entry into it.
I suggest creating a small ajax form. Create a "Add Meter Reading" button in it, which on submission would create a meter reading node in the server. The ajax form should have parent information in a hidden field ( i.e. the Meter id). The ajax response for this form could be another script to load/refresh the view on client side.
Client side code to refresh the view can be found in Views Autorefresh submodule in Views Hacks.
If using views megarow you would have to add another jquery function on ajax response after view is refreshed - Trigger edit button.
Otherwise you may have to add some classes or theme to newly created rows in view to bring them to focus.
It is important that the entire views refreshes, so that drupal behaviours are attached to the newly created entry in table.
I don't know if there is one module which will meet all your needs but you may be able to use some in combination.
Views Bulk Operations (VBO) - has Drupal 7 support
This module augments Views by allowing bulk operations to be executed
on the displayed rows. It does so by showing a checkbox in front of
each node, and adding a select box containing operations that can be
applied. Drupal Core or Rules actions can be used.
editablefields - Drupal 7 version in dev
This module allows CCK fields to be edited on a node's display (e.g.
at node/123), not just on the node edit pages (e.g. node/123/edit). It
also works within views etc. Anywhere a 'formatter' can be selected,
you can select editable (or click to edit).
editview - no Drupal 7 support yet but I thought I would mention it in case you're able to adapt the code yourself
Editview is a plugin for the Views module. It allows you to create a
view in which the nodes are editable, and new nodes can be created.