What is form collection in ZF2 - zend-framework2

What is ZF2 form collection ? When should we use form collection ? I think ZF2 document has no clear definition about Collection.
Can any one explain with the example?
Thanks for reading.

A Form Collection is used whenever your form is supposed to display multiple instances of a certain object.
For example: You have one Album-Object and you have a Track-Object. One Album is supposed to have multiple Tracks. Instead of adding just one Track per form you can create a collection to allow for multiple tracks to be added at once.

Related

Passing a Collection from VBA to a form

I have a an MS Access database with nine tables. The main form will be driven by a query linking the two main tables. When I pull up any one record ("family within a house"), I have a lot of variable data to pull into the form (how many family members, names of each, other specific information) to retrieve from the other seven tables. I created a VBA module, linked to this form, which is triggered when a record is loaded. The code aggregates all the family member data into a Collection of "person" elements. All of that works, as evidenced by the "Immediate" window in VBA. The "person" object is defined as a Class Module with all the relevant attributes (firstname, lastname, email, is-parent/is-child, etc).
Where I'm stuck: how do I access the collection within the form, so I can start populating elements? I haven't been able to find any documentation to do this, nor any similar questions asked/answered online. Next step will be creating all the elements dynamically, but right now, being able to create a static element and setting the control source to (at least some component/value within) the collection would be a huge help.
My VBA form module has a method, "Private Sub Form_Current()", which generates the collection when the current record is changed.
Thanks in advance...
Got my answer: "you don't". Set the element values in code, rather than trying to pass the collection the form.

How to use same scripts in views

I have a view for creating an entity by filling a form. That form contains several inputs and 2 datatables table. i write a considerable amount of JavaScript code for initialization and validation of the inputs. For editing the entity, i need the 95% of inputs and JavaScript codes.
First, I tried to move the common codes to a partial view but some of them worked and some of it didn't work. For example the tables not initialized.
As a second approach, I can also write a lot of if-else to check the current page (between Create and Edit) and do proper action.
How can i have two views and common codes in both? Is there a better or functional approach?
save your javascript code as js file. Drag and drop its link where you want to use it :)
You can use the same view for Create and edit functionality.
And regarding the inputs, you can take one property in the model which will indicate whether to show or not to show that input on UI.
Model:
For eg. Public string displayInput=[none/block]
view:
You need to set the value of displayInput field properly when you want to show all fields and when you want to hide some fields.

Partial Page Postback'ish MVC 4

First, I apologize if this is a dumb question, but I'm new to MVC and am trying to get up to speed as quickly as possible. I have spent hours searching for answers and even went and bought a book on MVC 4, but it still didn't answer my question.
I have a form I'd like a user to fill out to add a new product to the catalog. They choose the category, enter the name, a description, etc.. On the same page I'd like them to be able to add sizes or product options such as Small, Medium, Large, etc.. The problem is I'm not sure how to go about this.
I need to temporarily store the size options for example in some sort of collection until the user actually 'saves' the product, then I need to be able to read the collection. What I'm trying to avoid is to have the user add the basic product info, then save it, then select it, then choose to add options to it. I'm trying to just do it all on one form. Any help would be greatly appreciated!
There is nothing preventing you creating a view model with its own collections for the detail items and have those mapped to some sort of javascript control for selecting multiple items such as one that writes to an mvc hidden form control.
The controller handling the postback will simply create the master model from the postback data (the updated view model) and then create the child records. The whole thing could be achieved with ajax calling a controller action that returns a partial view of the updated ui.
Similar to this but have the list as a property of the master model
http://www.stevefenton.co.uk/Content/Blog/Date/201002/Blog/How-To-Handle-Multiple-Select-Lists-In-ASP-NET-MVC/
A little more advanced on how to manage your own bindings http://www.dotnetcurry.com/ShowArticle.aspx?ID=584
Sounds like u need to roll your sleeves up and get a control written in javascript that allows child items to be added client side whist serializing e.g. Into json when they save and saving it to an mvc hidden control ready for postback. Use json.net to hydrate these values into your pocos. http://erraticdev.blogspot.co.uk/2010/12/sending-complex-json-objects-to-aspnet.html

MVC child - parent on the same page

I'm pretty new to using MVC3 so hopefully the terms I'm using are all correct.
Basically I'm looking for a way (if possible!) to have a parent and child(s) record be added on the same page. I'm able to get the page to display correctly, but I'm unsure how to update the parent model.
In my Create view I have all the fields for the parent, and I'd also like to add the child records to the form as well.
I'm currently using Html.RenderPartial("CreateChildView") to display my Create child page within the parent.
I'm also using Html.RenderPartial("IndexChildView) to display my child records that have been added.
Where I'm stuck at is how to update the Parent model from the "CreateChildView" from above,
I've tried adding a submit button to the child view but I'm not getting the results I was hoping for.
the equivelent c# code that I'm kind of looking for is:
ParentObject.ChildObject.Add(new ChildObject)
and then a way to display this correctly
Thanks in Advance
Place both partials in div with ids. Post data with ajax from "CreateChildView" and update "IndexChildView" with response.

Displaying and updating multiple models in one view

I have 3 different models, business_info, business_hours, business_vacations.
I have one view that displays all that information, so I made a new controller called business_all to gather all that info.
But when it comes to editing the individual parts within the page I'll be calling each of those 3 individual controllers to update, delete etc, then send back the updated data for that particular model.
Given that, should I skip having the business_all controller and instead, when the view is loaded have 3 ajax calls to each controller to get the relevant info?
one alternative is to make a non persisting model called business_all that has fields that combine the three models with its own validation and so on. and when persisting it actually saves to the actual models.
this way doing the forms and so on are easier as you can do form_for (BusinessAll.new ... ...) and so on.

Resources