I have a Map of two custom objects as property in my Model object that I display in JSP by directly binding it in path and items attribute of <form:select>
<form:select id="selectedpbrtypes" multiple="true" items="${prescriber.selectedpbrtypes}" path="selectedpbrtypes"/>
On submission I get a comma separated string of all selected values of <form:options>.
Now the issue that I want to access separate property of Model object
private Map<Integer, PrescriberTypeModel> availablePbrTypes
And use availablePbrTypes to fetch all PrescriberTypeModel based on values in comma separated string in setAsText method of property editor and create a Map.
Please help as I have no idea how to access some other object in property editor.
Related
In buildForm() I would like to extract the full id/name of the current form field node. $builder->getName() returns only the name of the current node but I need the full property path, for example:
id="type_employments_0_location"
name="type[employments][0][location]"
Is there any way to generate this while building the form?
I'm working on a custom mandatory field type extension that looks up the "mandatoriness" of each field as the form is built; hence I need the full property path in buildForm() so that I can modify the options array.
From the FormConfigInterface, You should be able to use $builder->getPropertyPath().
It will return a PropertyPathInterface object, just use it as a string to get the real property path as string (i.e. print $builder->getPropertyPath() will give type[employments][0][location]).
Actually, it's pretty easy.
For every field type has many variables assigned.
<label for="{{ form.fieldname.vars.id }}">...</label>
From symfony doc (Form Variables Reference):
variables are common to every field type. Certain field types may have
even more variables and some variables here only really apply to
certain types.
Assuming you have a form variable in your template and you want to
reference the variables on the name field, accessing the variables is
done by using a public vars property on the FormView object.
Form Variables Reference
In a nutshell: The full property path generated by the form framework is not available to buildForm() but is available to buildView() and finishView(). Use those if you need access to the full property path.
I need to get the selected value of a parameter and use it in my code. Is there any events where I can capture the parameter values. Please let me know
It looks as if the answer is yes.
There's an event on the ReportViewer web control called SubmittingParameterValues that you can handle in the host page. This has a ReportParametersEventArgs parameter, which in turn has a Parameters property.
The Parameters property is a collection of ReportParameter objects. The ReportParameter class has Name and Values properties.
You can use the Name property to find the parameter you're interested in. The Values property, which is a collection of strings, should contain the value submitted.
I have a form tha contains a TreeView with many Textboxes in each node. the TreeView created dynamically with Razor and I don't know the name or ID of textboxes.
How can I get the value and id of all textboxes in the controller in MVC3 ?
I would use the FormCollection class. Read about it here http://msdn.microsoft.com/en-us/library/system.web.mvc.formcollection.aspx
In your controller;
Public ActionResult ActionName(FormCollection formCollection){
}
This allows you to gain access to any of the keys posted.
Request.Form.AllKeys will allow you to access all the fields in the form's ids. Then you can use Request.Form[id] to access the value.
Edit: Possible Dupe:How can I get all element values from Request.Form without specifying exactly which one with .GetValues(“ElementIdName”)
What is the difference between prependClientTransformer and appendClientTransformer in Symfony2 form? When should I use prependClientTransformer, appendClientTransformer. Any examples?
What I've understood about this :
The FormType you're applying the DataTransformer to has a parent Type defined in getParent() method.
prependClientTransformer will apply passed DataTransformer BEFORE those ones that are applied from parent Type.
appendClientTransformer will apply passed DataTransformer AFTER those ones that are applied from parent Type.
As you see in the source these methods are used to control the calling sequence of the clientTransformers which are used for transform the field data. It is useful when you create custom field type.
For example you want to create a tag field type which will take comma separated values which will internally transformed to array of tags. You set its parent as text field type. You also created a transformer for tag type which transforms array to string or vice-versa. Now your tag type will have two clientTranformer, ValueToStringTransFormer and your transformer at last position. So when you bind data to a form or submit the form symfony will transform the client data to string and convert the transformed string then to array (as described here). And for reverse case it will transform the array to string and then string to client value (as defined here). Haven't found a use case for prependClientTransformer though :).
In database I have Contacts table:
ContactID (int)
FirstName (varchar)
LastName (varchar)
...
XmlFields (xml) // This field is xml type
To create a new contact, I created two classes - one for regular fields and other to display fields from XmlFields field.
In Controller, I have following:
public ActionResult Create(Contact contact, FormCollection collection)
...
Regular field I catch with contact object and those that need to be stored as xml in XmlFields I try to catch with collection object. Problem is that collection object catches all fields, so I wonder if it is possible to isolate xml fields when posting to a specific object so that I can easily manipulate with them.
I need this in separated objects because these xml fields are going to be generated dynamically and will be different for every user.
Thanks in advance,
Ile
You can separate fields like:
public ActionResult Create(int ContactID, string FirstName)
And pass the raw data to the XML... There isn't any automatic way for MVC to know where to push what data to, unless you consider creating a custom model binder: http://davidhayden.com/blog/dave/archive/2008/09/08/CustomModelBinderMoreUIValidationASPNETMVC.aspx which is another valid option.
HTH.