Current behavior is that, if you try to save a node to state X with some requirements not met, the node will save, but the state transition will be prevented.

It would be more intuitive if it actually prevented the form submission.

I have a fairly extensive patch here, that implements this functionality.

On form validation, it checks the state that you are going to, and makes sure that you meet the requirements of that state. If not, it blocks the form submission.

It continues to block state transitions, as well. That way, there's no getting around the requirements by using the "Workflow" tab or some other state transition mechanism.

As an added bonus, you can now set fields to "Required" in the traditional field settings. If you do this, then radio buttons won't have the "N/A" option (this may or may not be desired behavior. If the N/A option isn't there, you can never unset the radio once it's set. That's good for our purposes. We have a workflow state called "draft". We want our nodes proceeding inevitably toward complete, we don't want people removing data from there. If we wanted people to be able to unset radio buttons, we would not set it to required in the field settings.)

Also, a big bonus: This patch adds integration with conditional_fields, as requested in #869868: work properly with conditional_fields. I actually borrowed some code from conditional_fields -- the code that does the form validation -- so I got familiar enough with it to figure out how to integrate it here.

Finally, this patch integrates with workflow_extensions. Workflow_extensions removes the workflow-state radio buttons and adds a new submit button for each state transition. However, workflow_extensions integration only works with the patch from #1313490: #to_state when staying in a node.

So, this patch is kind of an overhaul, but I think it works in a far more intuitive manner than how wf_required_fields currently works.

Comments

galaxor’s picture

Status: Active » Needs review
galaxor’s picture

One thing I forgot: In this new patch, you can change the setting of requiredness, even if the field is marked as globally required.

galaxor’s picture

StatusFileSize
new20.2 KB

One more thing I forgot to include in my patch: wf_required_fields needs to have a higher weight than fieldgroup if my changes are going to work. I made an install file that makes sure this is the case.

galaxor’s picture

StatusFileSize
new20.2 KB

Whoops, that last patch only set the weight when you did a database update. The query that set the weight had a typo for the case when you installed the module new.

Here is a patch with that typo fixed.

JCB’s picture

StatusFileSize
new40.63 KB

Hi galaxor,

I am experiancing problems & receiving errors after applying the patch.

I implemented both these patches
http://drupal.org/files/to_state_nospace.diff
http://drupal.org/files/wf_required_fields_validation_install.diff

None of my fields are marked as required on the cck side; only on the workflow required field.

Error I am receiving:
warning: Invalid argument supplied for foreach() in /usr/www/users/magicq/sites/all/modules/wf_required_fields/wf_required_fields.inc on line 167.

Problems Experiencing:
My fields that were required is not required anymore.

I attached my two modules (patched).

I am currently working on a project that is on deadline and would very much appreciate it is you can give me feedback asap.

Thanks in advance.

Kind Regards,

JC Booysen

galaxor’s picture

Hm. Perhaps the weights didn't update properly?

wf_required_fields needs to have a weight of 11. Did you run the update.php? Maybe I did something wrong and that didn't work. I use an oracle database backend, which is highly unusual. Maybe the weight updating query doesn't work in mysql?

The weights I have are:
NAME,WEIGHT
workflow,0
workflow_extensions,0
conditional_fields,10
wf_required_fields,11

JCB’s picture

Thanks for your prompt response.

I had to revert to standard module in order to get the project finished when I picked up a problem with the stable module.

This is probably not the place to post the problem so you can just take note of this.

I have multiple fields of which only a hand full are visible on each workflow state.
State 1 - field 1, field 2, field 3
State 2 - field 4, field 5, field 6
State 3 - field 7,
Etc.

However the problem came in not with the required fields, making the fields required works fine - however after passing required fields validation, the status was not allowed to update.
Received a message "Cannot promote .... The following fields are empty"
And then it will validate against required fields of the following state, instead of the current state.

So updating a node from state 1 to state 2 will validate required fields of state 1, but will not promote as the fields in state 2 is being listed as required.

This might be caused by me reverting to the stable version after trying the patch.

Fortunately it was just something small that caused the problem and I managed to fix it by changing a variable in the wf_required_fields.module file.

case 'transition pre':
      $missing = wf_required_fields_get_missing_fields($node, $new_sid);

To

case 'transition pre':
      $missing = wf_required_fields_get_missing_fields($node, $old_sid);

Hope this might help someone.

JCB’s picture

I forgot to answer your question

wf_required_fields needs to have a weight of 11. Did you run the update.php? Maybe I did something wrong and that didn't work. I use an oracle database backend, which is highly unusual. Maybe the weight updating query doesn't work in mysql?

I checked and the weights are as indicated:
workflow,0
workflow_extensions,0
wf_required_fields,11

I don't have conditional fields installed (thus missing):
conditional_fields,10

JCB

paultrotter50’s picture

Hi Galaxor. Cheers for the patch. When I tried to install the most recent version using cygwin I got:

Hunk #1 FAILED at 9.
1 out of 1 hunk FAILED

However the patch does seem to have worked, so I'm not quite sure whats up with that. Thanks for working on this patch - v useful.

paultrotter50’s picture

Has anyone got the patches to work to make a checkbox required for form submission. I know required checkboxes had a bug in core code, but the patch (http://drupal.org/project/checkbox_validate) doesn't seem to help their use in workflow required fields, and I can't get them to highlight when not filled in or use them to prevent the form from submitting. Has anyone else run across this? Any tips?

paultrotter50’s picture

Issue summary: View changes

Change the issue numbers to links.