When using a date field as a referenced field and leaving a blank row when using multiple value reference on save a validation error is thrown.

Comments

boombatower’s picture

StatusFileSize
new28.28 KB

validation issue

dboulet’s picture

I'm seeing this, as well as extra validation errors because my date fields are required. I guess what we would need to do is to skip validation if all fields are blank?

very_random_man’s picture

Status: Active » Needs review
StatusFileSize
new3.3 KB

I've fixed this.

I've used the form_alter hook to swap auto-create sub-field validation with a wrapper. The wrapper examines the nodereference field to decide whether or not to run the original field validation.

I've attached a patch. As with the other issue for this module I stuck a patch on, be aware that i've never made a patch before and it may not work! Let me know if that's the case and what I need to do to make it work.

Cheers!

boombatower’s picture

Status: Needs review » Needs work

Should the validation stuff be inside of nodereference_field_element_alter() instead of looping through everything again?

very_random_man’s picture

Good point. I'd originally written these customisations in a separate module as I wasn't sure i'd have time to come up with a generic solution and just copied it across to the equivalent place. I'll play with it some more and tighten it up when i get a moment today.

very_random_man’s picture

Version: 6.x-1.0 » 6.x-1.x-dev
Status: Needs review » Needs work

Ok. Bit later than expected but I've got a splendid patch now.

As suggested above, I've integrated the validation code properly.

I've also fixed this other issue:
#631864: Certain widget types don't display on multiple value autocreate fields

Also, I've made it so you can use node references and multiple value fields. This required a bit of restructuring of how the fields are stored in the node so instead of being:

nodereference_field_FIELDNAME
[0] = row 0 value
[1] = row 1 value

..etc
its now

nodereference_field_0_FIELDNAME
[0] = row 0 value 1
[1] = row 0 value 2

nodereference_field_1_FIELDNAME
[0] = row 1 value 1
[1] = row 1 value 2
..etc

It probably ought to have some sort of checking in place to check for infinite reference loops but that shouldn't be too hard to add if required.

I've not had time to reword the content_field blurb so it still says you can't have multi fields or nodereferences.

Enjoy!

very_random_man’s picture

whoops. forgot to add the patch!

very_random_man’s picture

Version: 6.x-1.x-dev » 6.x-1.0
Status: Needs work » Needs review

.... and it appears i forgot to change status too! ;-)

Status: Needs work » Needs review