开发者

Submitting variable length forms based on user input

开发者 https://www.devze.com 2023-04-06 01:26 出处:网络
I\'m trying to wrap my head around this.My language is Java using PlayFramework but I think any answer using php, or ruby on rails would get me in the right direction.Basically the user can add or tak

I'm trying to wrap my head around this. My language is Java using PlayFramework but I think any answer using php, or ruby on rails would get me in the right direction. Basically the user can add or take away number of pallets in this form. There needs to be so开发者_如何学JAVAme javavscript calculations per tab also. Everything is fired using a input change jquery event so there is no submit buttons. My first mockup used UUID's but that seemed to get me nowhere.

Submitting variable length forms based on user input

Submitting variable length forms based on user input

What happens is each tab is reponsible for doing calculations like perimeter. My first question is how to call javascript for the specific tab. I first did it with UUID's and separate scripts for each tab. This didn't seem correct.

My second problem is submitting this data. Obviously the name parameters need to be different. So I'm scratching my head on this. Every pallet would be tagged with an id so I'm not worried about the backend as much as I'm trying to figure out how structure the front end and the controllers.

Any help would be great. Thanks.


On the javascript part, assuming all the tabs have the same structure, create a generic method that receives and id (id of the tab) as parameter, and then retrieves the proper fields form the calculation. Something like:

function doCalc(tabId){ //assumes jquery
  var tab = $("#"+tabId);
  var field1 = $("#"+tabId+"_field1");
  var field2 = $("#"+tabId+"_field2");
  //...etc to retrieve tabs
}

The method assumes that when you create a tab "tabId" and its elements, you generate the id of the elements with the formula "tabId_", which will facilitate finding them.

About the submission, using Play! you should check this section about Ajax requests. It could be as simple as doing the calculation (the method above) and at the end call a Play method via Ajax. This method would get all the parameters (id, values, etc) of a pallet (the pallet of the given tab) and save it.


For submission, I assume you are trying to figure out how to hold and pass the data in a bean. What about having a field as below:

LinkedHashMap<String, LinkedHashMap<String, Object>> field;

The inner maps would be the listing of the fields on a Pallet. The outter maps are the Pallets.

0

精彩评论

暂无评论...
验证码 换一张
取 消