Hi,
when I create a biblio entry and choose a type, say "Book", and then realize I mis-clicked and was going to select "Book chapter", I cannot change the type to "Book chapter" anymore, because on changing it the form_validate hook hits me about missing fields.

I guess you intend to work around this with $form_state['storage'] in the validate-hook, but since you mark e.g. the fields title and year as required, the normal drupal validate function will catch them. Instead of setting '#required' => $fld['required'] (and title/year harcoded additionally) you might leave all the required-attributes FALSE and loop about all fields that have $fld['required'] set in biblio_form_validate and issue a set_form_error for each of them.

This way drupal shouldn't do any checks when changing the publication type but leave it all up to your validate hook.

cu,
Frank

Comments

rjerome’s picture

I'm surprised that you can't change the type. On my systems, you get the error messages regarding missing fields but the type does in fact change.

This is one area that has been a chronic issue, mainly because of the way I've got this form setup. As you are no doubt aware, when the type is changed, that triggers a javascript submit of the form which in turn runs it through all the validation steps. I will give your suggestion a try and see how it works. The issue has been determining whether the submit came from the type change or from the submit button, and if I recall, there was no obvious way to determine that.

Ron.

Anonymous’s picture

You are right, the type indeed changes! I was so confused by the error messages that I didn't realize that the type had indeed changed :-D Sorry for that! So it would just be cosmetic to remove the warnings and not a real issue!

bekasu’s picture

Status: Active » Closed (fixed)

Closing issue.
bekasu

shaundychko’s picture

Status: Closed (fixed) » Needs work
StatusFileSize
new44.32 KB
new39.08 KB
new45.32 KB

Is the error really only cosmetic?

The screenshots show: newspaper form, book form, then the error message when changing from book to newspaper. Notice that in the last screenshot the Series Author should read Secondary Author for newspaper entries. All the forms look so similar it's hard to tell the differences, but the fieldset headings definitely are not updating when trying to change publication types, so I'm wondering what else isn't right...

shaundychko’s picture

StatusFileSize
new33.64 KB

another example is when changing from film to book. The book form should not have "Year Released" (which is held over from the film form)

This remains a problem in 6.x-1.x-dev

shaundychko’s picture

StatusFileSize
new1.22 KB

My solution to this has been to make two changes to biblio.module to remove the "required" status of the title and year field, and then check that they're set using a Rules form event.

The changes to biblio.module are:
line 1245:

      '#required' => FALSE,

line 1317

            '#required' => FALSE,

and then use the attached Rules feature (you'll need the Features module).

shaundychko’s picture

Status: Needs work » Active
david lesieur’s picture

david lesieur’s picture

Nah, it does not solve it.

But the problem is similar in that selecting a publication type submits a form whose validation fails, causing the loss of $form_state['storage']['biblio_type'], which Biblio needs to build the right fields for the selected publication type.

david lesieur’s picture

Ron has expressed the problem correctly above:

The issue has been determining whether the submit came from the type change or from the submit button

Perhaps this could be solved by adding an extra (hidden) submit button just for the publication type? It would allow us to check whether the publication type submit button was used and, in that case, alter the form accordingly to ensure that validation passes.

rjerome’s picture

This situation is exactly why Drupal 7 has a form element attribute "#limit_validation_errors" and it solves this issue completely. In the 6.x world probably the best we can do is remove the required flags on those fields and throw and error in the validation code, but only if the type HASN'T changed.

david lesieur’s picture

Status: Active » Needs review
StatusFileSize
new1.03 KB

How about this little hack?

rjerome’s picture

Status: Needs review » Fixed

Thanks David, that seems to work well, so committed...

http://drupalcode.org/project/biblio.git/commit/369f3b7

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.