10446 Posts in 2223 Topics by 1719 members
| Go to End | Next > | |
| Author | Topic: | 2229 Views |
-
[userforms] RequiredFields highlight?

4 May 2009 at 10:09pm
I'm probably missing out on something but is there an easy way to make required fields stand out with userforms?
Like adding a css-classname to it or a '*'?
I've always been using customforms before where you can add an extra class or check if it's required.
Don't feel much for subclassing all the fields...
-
Re: [userforms] RequiredFields highlight?

10 July 2009 at 3:40pm
Subscribe.
I can't see any way a user can differentiate a required field from a optional one until the validation tells them so.
Nor is there any way to even color them via css as the fields are all the same class.
Cheers
Aaron Cooper -
Re: [userforms] RequiredFields highlight?

13 July 2009 at 3:25pm
Did you ever get something sorted for this at all Dio?
I see another older post from you asking a similar question with no answer apart from yourself linking to the doku with setExtraClass method on it.
A better question really is: "Isn't this a pretty basic expectation to assume from a system that creates forms?". In fact, I could have sworn that this is exactly what it did prior to be being split from core.
I can't even see anything in the Bug Traca for this, but surely someone has it working due to lack of complaint.
Cheers
Aaron -
Re: [userforms] RequiredFields highlight?

13 July 2009 at 8:03pm Last edited: 13 July 2009 8:04pm
How about just writing (Required) after the tittle such as.
Name (Required)
Have seen websites do that before.
-
Re: [userforms] RequiredFields highlight?

13 July 2009 at 8:56pm
Yes, you can do that. However for the sake of clarity for the end user (clients). This should really be automated since the system allows them to select a field as required using a single checkbox in the admin.
The module builds these labels and fields based on selections made in the CMS. Which means that it really shouldn't be hard to apply a default "required identifyer" (*) and/or css extra class to the label at the same time.
I've dug into userforms and simply cannot find it.
Cheers
Aaron -
Re: [userforms] RequiredFields highlight?

13 July 2009 at 10:25pm
Double-A-Ron - make an enhancement ticket for userforms 0.2 on open.silverstripe.com. I will get this into the stable 0.2 release for you. I think the implementation of it would just be an extra class to the containing div. Adding * to the labels automatically may confuse some clients who think - hey its not there it in the cms, why is it there sorta thing so I would avoid that. But added a required class would be a acceptable solution.
If you want to undertake this work yourself then to add the class to the form field go line line 211 of UserDefinedForm.php
if($field->Required) {
...
$fieldToAdd->addExtraClass('required'); // add required class
$fieldToAdd->setLeftTitle($fieldToAdd->LeftTitle() . ' *'); // add a * to the label
} -
Re: [userforms] RequiredFields highlight?

14 July 2009 at 11:46am
Thanks Will,
That's one of the blocks I played with earlier to no avail, although I wasn't attempting to addExtraClass to $fieldToAdd.
So that works. I do notice that this extra class is applied to the encapsulating div of the entire field (label and input). Like so:
<div id="EditableTextField355" class="field text required">
<label class="left" for="Form_Form_EditableTextField355">First Name</label>
<div class="middleColumn">
<input type="text" class="text required" id="Form_Form_EditableTextField355" name="EditableTextField355" value="" maxlength="32" size="30" />
</div>
</div>So it's not applying the required class to the label itself (as you stated). This is fine. I just set my css like this to make all required labels red:
.field.text.required label.left{
color:#F00;
}This probably makes sense (rather than adding the class to the label) as some people might want to do CSS things to the input on required fields too.
The line $fieldToAdd->setLeftTitle($fieldToAdd->LeftTitle() . ' *'); doesn't appear to have any effect what-soever sorry.
Would you be open to the idea of adding a field to the form CMS setup where users can enter their own "Required identifyer"? e.g. Some clients might choose to have a "*", some might want "(required)". This can be blank by default and if not, be appeneded one from the label in it's own <span> so CSS tricks can be applied to this. This one isn't a biggy for me, but it does appeal.
Ticket created for the CSS class: http://open.silverstripe.com/ticket/4379
Ticket created for adding the "Required Identifyer" field to the CMS seperately, as you may not be keen on the idea. http://open.silverstripe.com/ticket/4380Cheers
AaronCheers
Aaron -
Re: [userforms] RequiredFields highlight?

25 September 2009 at 7:18pm
Expanding on willr's comment, this worked for me:
if($field->Required) {
...
$fieldToAdd->setTitle($fieldToAdd->Title()." <span style='color:#F00'>*</span>");
}Cheers
Richard
| 2229 Views | ||
| Go to Top | Next > |



