Jump to:

10849 Posts in 2516 Topics by 1792 members

All other Modules

SilverStripe Forums » All other Modules » [userforms] RequiredFields highlight?

Discuss all other Modules here.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1 2
Go to End
Author Topic: 2551 Views
  • dio5
    Avatar
    Community Member
    501 Posts

    [userforms] RequiredFields highlight? Link to this post

    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...

  • Double-A-Ron
    Avatar
    Community Member
    603 Posts

    Re: [userforms] RequiredFields highlight? Link to this post

    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

  • Double-A-Ron
    Avatar
    Community Member
    603 Posts

    Re: [userforms] RequiredFields highlight? Link to this post

    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

  • Thermalzombie
    Avatar
    Community Member
    27 Posts

    Re: [userforms] RequiredFields highlight? Link to this post

    How about just writing (Required) after the tittle such as.

    Name (Required)

    Have seen websites do that before.

  • Double-A-Ron
    Avatar
    Community Member
    603 Posts

    Re: [userforms] RequiredFields highlight? Link to this post

    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

  • Willr
    Avatar
    Forum Moderator
    5464 Posts

    Re: [userforms] RequiredFields highlight? Link to this post

    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
    }

  • Double-A-Ron
    Avatar
    Community Member
    603 Posts

    Re: [userforms] RequiredFields highlight? Link to this post

    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 &nbsp; 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/4380

    Cheers
    Aaron

    Cheers
    Aaron

  • RichardMortimer
    Avatar
    Community Member
    15 Posts

    Re: [userforms] RequiredFields highlight? Link to this post

    Expanding on willr's comment, this worked for me:

    if($field->Required) {
    ...
    $fieldToAdd->setTitle($fieldToAdd->Title()." <span style='color:#F00'>*</span>");
    }

    Cheers

    Richard

    2551 Views
Page: 1 2
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.