Add a user-defined "required" indicator to tabs containing required fields

loze - January 23, 2009 - 18:32
Project:Vertical Tabs
Version:6.x-1.x-dev
Component:User interface
Category:feature request
Priority:normal
Assigned:lesmana
Status:needs review
Description

If a fieldset contains a required field, there should be some sort of indicator on the tab, or a required class so you could indicate it via css.
Maybe there is an option to do this but im missing it.

awesome module!

#1

loze - January 23, 2009 - 18:33
Title:Add a required indicator (asterik) to tabs containing required fields» Add a required indicator (asterisk) to tabs containing required fields

#2

lesmana - February 16, 2009 - 06:24
Assigned to:Anonymous» lesmana
Status:active» needs review

This is a javascript-only solution; I think that's appropriate since we want the module behavior to devolve gracefully if JS is disabled.

AttachmentSize
363279-vertical_tabs.js_.patch 862 bytes

#3

rick_deckard - March 24, 2009 - 05:10

Thanks lesmana.

It worked in FF3 and Chrome, but it doesn't work in IE7 on XP for me.

A little debugging. For a required field,

$(this).attr('href')

returns "group_required" for a required field in Chrome (strips off the # sign)
returns ttp://domain.com/node/10/edit#group_required (strips off the h)

In other words, lets say the fieldset is named 'stuff', in IE, $(this).attr('href') evaluates to the http://example.com/node/1/edit#stuff or http://example.com/node/1/edit#group_required, whereas it Chrome and FF, it evaluates to simply #stuff or #group_required.

#4

quicksketch - April 3, 2009 - 07:11
Status:needs review» needs work

I'm not sure if this should be added, since the core version (#323112: Vertical Tabs) does not include this functionality. I'm open to discussion on the matter though. Either way this patch needs some work as per #3.

#5

lesmana - April 3, 2009 - 16:38
Assigned to:lesmana» Anonymous

quicksketch: I think the 6.x functionality that allows custom CCK fields and fieldsets to be rendered as Vertical Tabs makes this issue relevant to this branch, as opposed to the 7.x core version in which (AFAIK) none of the fields in the default vertical tabs are required.

That said, the approach I took in the patch above isn't exactly elegant, so if anyone else wants to take a shot, have at it.

#6

lesmana - April 10, 2009 - 17:17
Status:needs work» needs review

Here's another go at the patch in #2, with more processing of the 'href' attribute to account for browser differences. It should work in all cases now. Doing it this way seems like a workaround to me still, though. If the new branch to be backported from D7 still includes the option to render CCK Field Groups as Vertical Tabs, this issue should be reworked from scratch.

EDIT: oops. don't use this one. Use the one in #10.

AttachmentSize
vertical_tabs-363279.patch 1.46 KB

#7

SocialNicheGuru - April 10, 2009 - 00:26

I get popups for each group that I have defined regardless of wheather it is a manditory field or not.

#8

lesmana - April 10, 2009 - 05:29

activelyOUT: what browser are you using?

#9

SocialNicheGuru - April 10, 2009 - 13:31

firefox

#10

lesmana - April 10, 2009 - 17:16

oh, whoops, I see what you're saying. That was stupid of me. Here's the same patch as #6 without the JS alert boxes.

AttachmentSize
vertical_tabs-363279-2.patch 1.45 KB

#11

quicksketch - May 21, 2009 - 06:21

After running into this frustration a few times, I have to agree, it's important. Let's start here, but make sure that Drupal 7 gets this same feature (it'd be a shame to *loose* functionality in Drupal 7). We should also also activate tabs when they contain form errors, but let's tackle that separately.

#12

crea - June 4, 2009 - 12:45

Is asterisk actually good for this ?
For field it is obvious and is established UI pattern, but for tabs ?

Some time ago I investigated different UI patterns and there was 2 things to remember
1) Using "(required)" after brief description of field is good and established pattern
2) If there are many required and few are optional, putting (optional) after optional fields is better.

Can this be made themable so we just put asterisks by default and let user decide what's more convenient to him ?

#13

quicksketch - June 5, 2009 - 03:39

The patch as it is currently does *not* actually require the use of an asterisk. It will scan the contents of the field for anything that contains <span class="required"></span>, then duplicate that span (and its contents) and put it on the tab. So if the convention on the site uses "(required)" next fields, the tabs will contain the same string. I think it's a good approach generally.

In the rare circumstance where users have taken the effort to theme form elements so that they contain "(optional)" (and I note this is very, very, very rare in the Drupal world) instead of an asterisk for required, they can still get the same effect if they wrap the text in a span with the class "required". It'd be a somewhat backward class name of course, but I have to reiterate that's an extremely rare situation. If Drupal provided a better mechanism for specifying which fields were optional with a property like #optional = TRUE, then it'd be worth another condition to check for another span class, however there's no standard on this because generally forms in Drupal don't ever use that approach.

I'm definitely not arguing the practices that sometimes an asterisk is not sufficient or that specifying fields as "optional" is more appropriate than marking required (it really often is), but instead that those issues are general core problems, and not something specifically affected by this patch or Vertical Tabs.

Edit: Added <code> tags around the span.

#14

crea - June 6, 2009 - 23:30
Status:needs review» needs work

Patch no longer applies.

#15

Cliff - September 19, 2009 - 17:36
Title:Add a required indicator (asterisk) to tabs containing required fields» Add a user-defined "required" indicator to tabs containing required fields

Revised title to more accurately reflect intended action as described in #13.

#16

fourmi4x - October 27, 2009 - 15:28

Hi,

I would really enjoy to have an asterisk for the required fields, This is definitely a very good idea.

But I looked into you patch and I don't know where I should paste it in vertical_tabs.js... (I don't know Javascript at all...)

Could you tell me how to implement this patch ?

Thanks a lot if you can !

#17

lesmana - October 28, 2009 - 00:24

Here's a rewrite of the patch against the current dev release. The basic principles described by quicksketch in #13 are the same. Since I was poking around in there anyway, I also put in tab activation for validation errors, per #11.

AttachmentSize
vertical_tabs-363269-3.patch 1.48 KB

#18

lesmana - October 28, 2009 - 00:26
Assigned to:Anonymous» lesmana
Status:needs work» needs review
 
 

Drupal is a registered trademark of Dries Buytaert.