Symfony2 integer type and NotBlank constraints are triggered at the same time - forms

I'm trying to validate a field in a form with the NotBlank and Type constraints. My problem is that when I enter a value that doesn't match the type both error messages are displayed. I have seen other answers that suggested that the field type should be changed to text.
Unfortunately, changing the field type to text and leaving the constraint for integer type will raise the validation error all the time.
Does anyone know of any solution to this problem? I'm using Symfony 2.0.4

What type do you have assigned in the Entity's property that matches this field?

Related

How to get column name for a unique_constraint violation?

I am using the pq driver and I'm wondering why the pq.Error gives an empty Column when I face a unique constraint violation.
I could parse Detail but is there any reason why Column would be empty? It would be preferable if I could just get email from Column instead of parsing Detail
Here is what the error looks like:
Severity:"ERROR"
Code:"23505"
Message:"duplicate key value violates unique constraint "unique_users""
Detail:"Key (email)=(user3#email.com) already exists."
Hint:""
Position:""
InternalPosition:""
InternalQuery:""
Where:""
Schema:"public"
Table:"users"
Column:""
DataTypeName:""
Constraint:"unique_users"
File:"nbtinsert.c"
Line:"534"
Routine:"_bt_check_unique"
Unfortunately, the Column value is empty. I'm trying to come up with error messaging for my application and I'm wondering if there is some way to get that information so I can enhance the message why the entity was not created and let the caller know the field (email in this case) as well.
The specific error message (including the violated constraint and column/value) is in the field Detail.
EDIT:
I guess Column is empty, because the unique constraint might affect multiple columns. Constraint offers the constraint name, in combination with Schema and Table you can look up this constraint in pg_constraint. Field conkey might hold the references to the covered attributes.

a number is required in the selection criteria when using a parameter

I am new to CR, and I think this is a complicated question. When a user runs the report, I want the user to input either nothing - which will get everything, or to input the values for that field - to get those specific values. Let me know if I am approaching this right.
I am trying to use a formula in the record selection formula editor. This formula references a parameter. I am trying to use WrkOrder.Center field - which is a number - in my selection criteria.
I am getting the error "a number is required here" in the record selection formula editor. I need to do a totext or cstr ? It just seems to still be incorrect.
if the center is blank then get all centers, else get the selected center input in the parameters by the users running the report.
if {?Center}="" then true else {?Center}=cstr({WRKORDER.CENTERNBR})
if {?Center} = "" then true else {?Center}={WRKORDER.CENTERNBR}
parameters to get what is either input or get all centers
First thing to check is the data type of your parameter and the data type of database field to ensure they match.
If you edit your parameter the first three controls on the form at the top are Name, Type, and List of Values. The Drop Down Box for Type will identify the data type of your parameter.
To identify the data type of your database field, find the field in the Field Explorer and if you don't already see a data type listed next to the column names for each table, right click on any field name and click "Show Field Type" and this will toggle the display of the field data type on and/or off. Its usually off by default I believe.
In order to use a comparison with the = operator, these two objects must have matching data types. You aren't able to change the data type of a database field, but you can change the data type of your parameter to match it.
Hopefully this will fix your error. The most common cause of the error message you are receiving is when one field is a Number type and the other is a Text type. Functions that convert the data will work in formula fields, but usually will continue to throw errors when used in selection expert formulas.

Clio API - What is the correct format to Update (PATCH) a custom field value for a matter

Anyone been able to successfully update the custom_field_values for a matter via Clio's API?
I'm trying to update the value for custom_field_values under a single matter. I'm able to send a JSON string using PATCH and update the default values for a matter like location or description using the following format
{"data":{"location":"Orange"}}
But when it comes to updating a "custom field value" I'm getting a 422 Unprocessable Entity error. I'm following Clio's v4 API Documentation and my understanding is that to update a custom_field_value you need the following JSON:
{"data":{"custom_field_values":[{"id":658213,"custom_field":{"id":139385},"value":"New Value Goes Here!"}]}}
However here is the message coming with the 422 error:
{"error":{"type":"ArgumentError","message":"An invalid argument was supplied: invalid custom field value id provided, acceptable format is <type>-<unique id>"}}
I can't interpret the part suggesting the acceptable format!
I've also tried sending the JSON in the following format which is closest to Clio's V2 API Docs for updating a custom field:
{"data":{"custom_field_values":[{"custom_field":{"id":139385},"value":"New value goes here"}]}}
But then this is what I get back:
{"error":{"type":"ArgumentError","message":"An invalid argument was supplied: custom field value for custom field 139385 already exists"}}
Please note that this is being tested in POSTMAN regardless of my development environment. I appreciate your response!
I've successfully created queries to update custom field values in matters many times, and these run all the time for me. I've compared your json to some examples of the json I'm successfully sending. Your syntax appears correct, but there's enough missing for me to only guess at where your mistake might be.
First, you're sending a PATCH to https://app.clio.com/api/v4/matters/{matter id}.json right? It took me a while to learn that you can't update the value of a matter's custom field with a query to https://app.clio.com/api/v4/custom_fields/{id}.json.
Second, just to clarify, the 658213 id you used above (the first id field) should be the unique id of this instance of your custom field. You won't get this until you've created an instance of the custom field particular to this matter. The second id field, where you've put 139385 is the id for the custom field itself, which you could get with a query to https://app.clio.com/api/v4/custom_fields.json.
If you're looking in the V.4 docs under Custom Fields, you won't find this, or at least I didn't. BUT you can find it in the intro section to the Matters portion fo the documentation: https://app.clio.com/api/v4/documentation#tag/Matters
Hope this helps. I'd imagine someone at Clio could help by verifying your error string is delivered when you have an incorrect custom field value unique id.
To further clarify Jacob's answer for everyone else:
custom_field{id} is the id given to a custom_field when it's created and will be the same for all matters or contacts it's used in.
custom_field_value{id} is the id given to an instance of the custom_field added to a particular matter and unique only to that matter
To add a custom_field to a matter for the first time the following format is used:
{"data":{"custom_field_values":[{"custom_field":{"id":123456},"value":"string or integer depending on the type of CF"}]}}
To update a custom field already added to a matter the following format should be used:
{"data":{"custom_field_values":[{"id":"text_line-1234567", "custom_field":{"id":123456},"value":"string or integer depending on the type of CF"}]}}
To delete a custom field already added to a matter the following JSON format is sufficient:
{"data":{"custom_field_values":[{"id":"text_line-1234567", "custom_field":{"id":123456},"_destroy":true}]}}
Format for updating a custom field already added to a matter:
{"data":{"custom_field_values":[{"id":"unique_instance_of_your_custom_field", "custom_field":{"id":'custom_field_id'},"value":"value which should be updated"}]}}
Here, the first id field should be the unique id of this instance of your custom field. To get this value follow this documentation section, app.clio.com/api/v4/documentation#tag/Matters and the second id field is the id for the custom field itself.

Symfony 2 collection unique elements constraint, mapping errors to children

I have a formtype with single field: collection, containing unspecified number of anonymous selects. Is there a way to check if there are duplicate choices using builtin constraints? In case I have to write constraint myself, there is another problem. If I add the constraint on parent, how can I add error to child on specific index? If I add the constraint on children using All - how can I access values of other children?
Selects are allowed to return null value. The form is not bound to entity.
Thank you.
Ok, after digging through 10 pages of Google and SO results, I didn't find anything. So, I dug further, and as often happens, I've found solution in unit tests - symfony github link to this specific thing which solved my problem.
Now when I want to add error to specific field in collection, I can do:
$this->context->addViolationAt('['.$i.']', 'Error in field %d', $i);
This is case for unnamed collection children with default numeric indexes, I didn't test it with named ones. Also - remember about collection having error_bubbling enabled by default.

Symfony2 Form Custom compound type

I'm trying to make a nullable integer, that is an integer which can also have a value set as null.
To do this, I was hoping to have an integer input with a check box to signify it is null (which could then have JavaScript hook up to disable/enable the integer input).
I see three ways of doing this:
Have a custom Type which has two fields.
Have a custom form widget which handles the two.
Some combination of one and two.
I'm not having any trouble with that, it's pretty straight forward.
What I can't seem to find any documentation about is how to get those two fields to funnel in to a single variable.
Any ideas?
The best way I can see is applying a form transformer to your form.
If the checkbox is checked you set null to your property, if it isn't you assign the value of your integer widget.
You can have a look here and apply this to your particular case.
Side note: I wouldn't do this in the controller, it's not his job.