Support from Acquia helps fund testing for Drupal Acquia logo

Comments

kenorb’s picture

Did some new date validation 'Date validation against another date field'.
I didn't test it properly, but it's a good start.

It works when submitting the node.
I was trying to test this field_validation plugin with ctools multistep wizard, but unfortunately it doesn't work, because hook_field_attach_validate is not executed when going to the next step.
So right now, I won't be continuing work on that patch because of my blocker: #1673502: How to use hook_field_attach_validate in multistep wizard form

g089h515r806’s picture

One way to solve it is support field token.
But token module does not support field token very well. I have create another token module "Compound token" which could solve the requirement of field validation, but it seems that my idea of "Compound token" could not be accepted.

Another way is use php validator, we need provide some code snippet, other developers could resue this code.

The third way is convert the code to a validator. We have include 20 validators, we need resctrict the total numbers of validators.
Maybe we could create another module field_validation_extras, which could include another 20 validators wich is less popular.

g089h515r806’s picture

Status: Needs review » Needs work

If this validator could solve this issue: #1325710: date range overlap validation.
Then we could include it in field validation. Date module is so popular that we could include 2 validators for it.

I have read the code of this validator, there are some works need to do:
1,need support all entity instead of only node.
2,need to implement operators "between" and "not betwwen"
3,user could config column, for Date field it could be "value" or "value2"
4,If possible, support all date type, such as Unix timestamp, datetime.

I think it does not matter to support multistep wizard form, field validation does not work correctly at some special case that is because they does not invoke hook_field_attach_validate or other reasons. An good example that support field validation very well is "field collection" module; some other modules such as "addressfield" and "link" module does not support field validation at some special case such as when a subform embeded into another form. For most common use case, Field validation works with almost all field modules.

I will test it on my local site if I have more time.

kenorb’s picture

Thanks for the response.
I was manage to add the validator manually by the code from here:
http://drupal.org/node/1673502#comment-6202836
But still it doesn't work properly with CTools.

I was thinking of creating dynamic select lists (like hierarchical_select), so once you select main entity_type, then the form will show for you appropriate bundle options, etc., instead of typing it manually (people don't know what to type in the textfield).
I've tried using this.form.submit();, but it throw the validation error on required forms.
We could also store all $entity_info into $setting and store it in javascript arrays, like in here:
http://drupalcode.org/project/postcodeanywhere.git/blob/refs/heads/7.x-1...
Having it in javascript arrays, we could assign the values by something like: 'onchange' => 'this.form.bundle.options = Drupal.settings.fv.entity_info[this.form.entity_info.value()]' (pseudo code)
Or if it's too complex, eventually write some short JS file.
If not, list all of the options and do the validation on submit.

Also I think it's good to include some standard setting widgets into parent class, like entity_type/bundle/field selection and reverse option (the same as with error message and column name), it'll be repeated very often, so it's bad to repeat the same code over and over again.

The other suggestion is to generate automatically default Titles (Validation of field_xxx) and Error messages, so user don't have to think too much.
'between' and 'not between' operators I've copied suggestions from Views, so it's not necessary to implement it now.
I think it's good to implement some basic working version, then once it's there, it's easier to improve it.

Regarding hook_field_attach_validate(), you could use form_alter and $form['#validate'][] with some conditions, it always works.

Once the date patch is ready, it's very easy to do the clone for #1650620: Field validation match against a field validator doesn't work properly with Email fields and #1541134: Validate two fields..

g089h515r806’s picture

"I was thinking of creating dynamic select lists (like hierarchical_select)",
I also thinking of this feature, but find that it is too difficult for me, so I decide to keep it simple to make it works first. It is acceptable for me to use input instead of select. Only a few people knows how to build the UI of Views, in the future, the UI of field validation will be similar of Views, but much simpler.

We could include "reverse option" first. It is very simple.

We could provide a default Error message, User could change it when they edit validation rule.

It is much better to use hook_field_attach_validate instead of "form_alter and $form['#validate'][]", hook_field_attach_validate suitable for every case, form_alter only suitable for common case.

g089h515r806’s picture

Issue summary: View changes

added sentence

g089h515r806’s picture

Issue summary: View changes

+1

ElegguaDP’s picture

Did some changes for validation between the two date fields using multiple validation rules.

manoloka’s picture

Hi there,

So, I've created and uploaded the file /plugins/validator/field_validation_date_field_values_validator.inc but I don't see how to it to use it.

Thanks
Manolo