In the 5/10/12 dev release, the problem with upgraded FAQ Categories fields still appearing on the Ask a Question form has been fixed. However, when asking a question I get this error, even though the FAQ Categories field isn't visible:
"FAQ Categories field is required."

I have this option checked on the FAQ Experts admin page:
"Only expert can categorize
If this box is checked, only an expert answering a question can add a category."

Related to: #1549620: Prompting user for category

Comments

stenjo’s picture

Assigned: Unassigned » stenjo

I've been trying to recreate this, without success.
I have been fiddling with the category handling a little, and may have inadvertently fixed this :-)
Could you provide more details on what exactly you did to make this problem occur?

jlea9378’s picture

Well my site is upgraded from drupal 6, so that might be a factor. The taxonomy field is labeled taxonomyextra for some bizarre reason now. Attached are screenshots.

To reproduce the problem on the 5/10/12 dev release:
1. Open browser and go to website.
2. Click "Ask a New Question".
3. Type question and optionally leave email field blank.
4. Click Save.

jlea9378’s picture

Sten, I updated to the May 15th dev release and now the FAQ Categories field is appearing (it's not being hidden anymore).

I looked at the code on lines 263 - 279 and it doesn't hide the taxonomy field. I think line 276 should be == 'taxonomy' instead of != 'taxonomy'.

I tried changing it to == 'taxonomy' and that caused the field to start hiding again. However, it still produces the error that "FAQ Categories is a required field".

stenjo’s picture

StatusFileSize
new22.08 KB

You are SO right in what you are pointing at. The comparison should of course be '=='! Thank you. Fixed that now.

I suspect your faq category field is set to required on the edit page on admin/structure/types/manage/faq/fields?
Category setting
If so ('cause this is the only way I am able to recreate the problem you are describing) I'm wondering if the correct fix of that is to require this to be unset, or if this should be forced programmatically off?
I'd be happy to have a small discussion about that.
At one level it does not make sense to have this enabled if only expert can categorise, but does that mean we should fiddle with settings sort of "behind the scenes"?
A middle path would be to indicate the need for switching this off in a message with a clickable link somewhere for the user to easily get to change the settings...

nancydru’s picture

Sten, first let me say how much I appreciate all that you have done with Faq_Ask.

In this case, I think the "middle path" would be the best course. I don't like second guessing the admin, even if it is likely to be a mistake.

jlea9378’s picture

Not sure what you meant by middle path, but in my situation:

  • For FAQ Ask (when a person asks a question), I want only the Expert to be able to set the category, and I want it to be required to be set when it is answered.
  • For the full FAQ creation page, I also want category to be required (so an Expert can create a new FAQ node manually from the Create Content list).

So basically I really do want category required, I just don't want site guests to be able to set the category, since they have no idea what category is appropriate in most cases. Is there some way to achieve this?

Would it be possible to change it to 'not required' programmatically on the short FAQ Ask form? Or perhaps do the opposite and have it kick back an error when the question is answered or on the full form if category isn't set?

stenjo’s picture

Ah, I see your point! Initially I thought this might be a new feature, but I see how this is actually the way it works in D6.
The challenge here is that the form field handling is different. The taxonomy field is not removed from the form as in D6 - only hidden, so if it is set to required, then it will show a warning as you say.
Will need to look into this and see if there is a way to make it NOT required just for the asker form.

stenjo’s picture

Think I've figured it out. The following code should handle this properly and setting the required taxonomy fields to FALSE so that the warning is not appearing when question is posted.

   // Check if only experts can categorize the question.
  if (variable_get('faq_ask_categorize', FALSE)) {
    // Hide all taxonomy fields
    $fields = field_info_instances('node', 'faq');
    foreach ($fields as $name => $properties) {
      if ($properties['display']['default']['module'] == 'taxonomy' && isset($form[$name])) {
       hide($form[$name]);                              // Hide form if it is a taxonomy field
       $form[$name][$language]['#required'] = FALSE;    // If hidden, then do not expect it to be required
      }
    }
  }

When answering, the taxonomy fields are required again.
Fix will be submitted later today and new dev package available tomorrow.

stenjo’s picture

@NancyDru,
Thank you for your comment. I see I am about to catch up on you on the number of commits ;-)
This is really also scratching my own back, and having people really using the module is a motivation boost. I've spent far more time on this than I initially thought.
It seems that my debate proposal might not be needed after all.

nancydru’s picture

Yes, after seeing his use case, which makes a lot of sense, I agree.

Be careful, module maintaining can be addictive. ;-)

jlea9378’s picture

Status: Active » Reviewed & tested by the community

Sten,

I downloaded the May 16th dev release but this fix wasn't in it. I manually added the line of code and it worked perfectly! Thanks!

stenjo’s picture

Status: Reviewed & tested by the community » Fixed

The fix will not appear until the may 17th release. (Constitution day of Norway actually :-) )

Status: Fixed » Closed (fixed)

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