How could i achive that HS has validation as other fields in node form, so when i dont input anything. Red square appaears around it? Currently nothing happens with html when nothing is selected and i did put required in that particular vocabulary. How could i achive this and add simple validation?

CommentFileSizeAuthor
#5 547134.patch3.63 KBwim leers
#2 Clipboard01.jpg3.1 KBMarko B

Comments

wim leers’s picture

Title: Validate HS - red square » Make HS Taxonomy required
Assigned: Unassigned » wim leers
Category: feature » support
Priority: Normal » Minor
Status: Active » Fixed

1) It's not a square but an asterisk.
2) You can simply enable the "Required" checkbox. That should work.

I just tested it, and an error appears if I don't select anything.

Marko B’s picture

StatusFileSize
new3.1 KB

Hmm are we talking about same thing? I was talking about pic i attached. It does say Some category is required but i dont get this border around field, can i get this also?

wim leers’s picture

Title: Make HS Taxonomy required » Upon validation error, show red border around Hierarchical Select
Category: support » feature
Status: Fixed » Active

Ah … you were talking about the border. Then this is indeed a feature request :)

Should be doable.

Marko B’s picture

Ok, any idea where, what? Just some css is needed to be changed upon validation, i would like to make it at least something custom if possible for now.

wim leers’s picture

Component: Code - Taxonomy » Code
Status: Active » Needs review
StatusFileSize
new3.63 KB

It is far more complex than just some CSS. From a report I'm writing on the vast array of deficiencies of the Forms API:

- The 'error' class, set by form_error(), should be applied automatically to
all child form items of a form item.
- It is in fact impossible to set the 'error' class for child form items: it
must be set in the validation stage (#element_validate), but changes to the
form item at this point are not stored (the form and thus the form items are
passed by value, not by reference). One might expect to be able to use
form_set_error() with the empty string (it is even the default), but due to
a bug in _form_set_class(), that is also impossible:
if (form_get_error($element)) {
$class[] = 'error';
}
Since the empty string cast to a boolean results in FALSE, the 'error' class
is never added. The only way around this is by setting your custom #theme
function for the form item, allow for the empty string to result in the
'error' class being added by calling _form_set_class() again there.

Despite all of that, I've been able to write a work-around. Patch attached. Let me know if it works for you too.

P.S.: this has cost me about 2 hours. Way more than expected.

Marko B’s picture

Hey Wim, tried it, it seems to work, but when i upgraded to latest HS version i got this problem http://drupal.org/node/538022#comment-1943380, thanx on this.

wim leers’s picture

Status: Needs review » Fixed
Marko B’s picture

You sure this one is working? I did clear cache, made update and i dont get red square as i did with patch on prev. version. Did u test it?

wim leers’s picture

Yep, I just tested it again, and it works.

Marko B’s picture

Hmm, ok, will do the same on blank installation. Somehow it doesnt do anything with my project with many other modules and custom theme. thanx

Marko B’s picture

I confirm its working :-) Seems i dont understand some stuff. I tought you applied this to todays version and u didnt. So commited means u will apply it when confirmed its working or?

I can confirm its working ok on my setup and will use it :-)

wim leers’s picture

Committed means it is in CVS (http://cvs.drupal.org). It's possible that it's not yet in the .tar.gz file (aka tarball), which is regenerated automatically on a daily basis, *not* after every change.

Thanks for your confirmation! :)

Status: Fixed » Closed (fixed)

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