简体   繁体   中英

Communicate forms in two pages (Javascript)

I have a form that requires another model to be saved before the first one:

I create a Proposal, and the proposal may have 1:n new Projects. When want to add a new Project, I have to save it first, choosing a base project (Already saved) and filling the wanted changes (In another tab). 表格1 表格2

When it's finished, I want to pass the saved project ID to the main form (Proposal), to a hidden field, to be saved.

Is there a way to use a value from this other form in another tab, on the first one? (Using Javascript)

Thanks!!

Can you give some more details on how you have build your application?

Do you render different tabs with javascript and do you save the project with an asynchronous call?

If this is the case, you can have the rails controller to return the id of the new project and store it in a hidden field with jQuery. $(hidden-field-selector).val(id) .

Are you redirecting between tabs (the rails way)?

Then you can add this id in a hidden field in your view. Perhaps this is not what you are looking for since you want to use javascript.

You could use this API: https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage . You need to register an event listener that listens to this value, and to fire the event once it's ready. You should have a handle for the opened tab otherwise you can't do it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM