Joi validation of dependent fields - joi

I am trying to set up a Joi schema for the following scenario:
Fields a, b, c. (they all have default value "", so the keys always exist)
Conditions:
When field a is filled, field b must be filled.
When field b is filled, field a must be filled.
When neither field a nor field b are filled, field c must be filled.
I have tried with Joi's .when, but faced circular dependency. With xor I have faced conflict between exclusive peers.
Any hints on how to approach this?
Thank you!

Related

Filemaker: Set field default value to 1

This might be a very stupid question but for the life of me I can't get it to work. I want to create a field in my table called "One" and it's value for all records in the table needs to be 1.
E.G.
Field1 One
A 1
B 1
C 1
.
.
.
I set the field to a number and tried the auto enter data and typed 1 in the data field but it's not updating the values.
Any help is greatly appreciated!
Thanks in advance
Simply put, Auto Enter applies to when the record is first created. One can do various other options, but this is the basic use of Auto Enter on a field. You set the value to be auto-entered in the field's options panel under Manage Database; a fixed value, calculated value and so on. This works on all versions of FileMaker.
That said, if this is to be a static value of 1 for all records, you might want to look into a calculation field with a result of 1 and possibly using global storage. This will not work if you need the user to be able to change the value.

Filemaker auto enter calculation - update with relationship

According to the Filemaker documentation,
If you select Calculated value, you can edit the field value in Browse mode (if Prohibit modification of value isn't selected). The value is calculated when you create a record, or when one of the referenced fields changes and the destination field is empty. (However, if you select Do not evaluate if all referenced fields are empty in the Specify Calculation dialog box, the value isn't calculated when you create a record and all fields referenced by the calculation are empty. Instead, the value is calculated when one of the referenced fields contains a value.
An auto enter calculation will be calculated if the reference field value used in the calculation is changed. I'm using a field in the relationship and from that same relationship I'm getting the value from a related table.
For example, relationship between table A to B is based on a field F1. In my calculation, I've
B::__text
Here, in this calculation I'm not using the field F1 but it used in the relationship between A->B. Whenever I'm changing the value of F1, Filemaker is updating the value of the auto enter calculation.
Is this normal? I don't find any docs related to this in the documentation.
Yes, it is expected behavior as long as the "Do not replace existing value of field" is not selected.

Enforce relationship match in FileMaker

I have two FileMaker tables that are linked using a relationship. The relationships matches based on the content of two fields:
TableA.Foo matches TableB.Foo
TableA.Bar matches TableB.Bar
Is there a way to enforce constraints on this relationship in FileMaker? When entering objects in TableA, I'd like to ensure that the values entered in fields Foo and Bar are such that there exists a corresponding record in TableB. Is this possible?
Bonus points if I could somehow autocomplete values of Bar based on the entries of TableB and the value already entered in Foo.
To answer your question as asked:
You can validate the Bar field (or any other field) by
calculation:
not IsEmpty ( TableB::Foo )
Set the validation to validate Always. This will throw a
validation error if you try to commit a record in TableA without
having a related record in TableB.
To auto-complete based on values in another field, you must format
the target field as Drop-down list with Auto-complete using a value
list.
Before defining the value list, set up a new relationship (using a
new occurrence of TableB) as:
TableA::Foo = TableB 2::Foo
Then define the value list to use values from TableB 2::Bar, show only related values starting from TableA.
I suspect there may be better ways to accomplish whatever you're trying to accomplish here.

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 integer type and NotBlank constraints are triggered at the same time

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?