Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Form Questions /

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

Form Validation: Require that one item of a SelectionGroup is selected


Go to End


49 Views

Avatar
NicolasLeuenberger

Community Member, 11 Posts

29 September 2017 at 2:52am

I want customers to rate a product from 1-4. I've made a form with a SelectionGroup containing 4 SelectionGroup_Item fields. I'm trying to validate if the customer has made a selection. Server-side it seems to work, the form only goes through when an option is selected. But no error-message is shown if none are selected, so the customer is left in the dark as to why their form wasn't sent.

Any ideas? Thanks very much!

$gradeBoxes = array(
    new SelectionGroup_Item($this->Note4, '', $this->Note4),
    new SelectionGroup_Item($this->Note3, '', $this->Note3),
    new SelectionGroup_Item($this->Note2, '', $this->Note2),
    new SelectionGroup_Item($this->Note1, '', $this->Note1),
);
$gradeField = new SelectionGroup('Grade', $gradeBoxes);
$gradeField->setCustomValidationMessage('Please select one.');
$fields->push($gradeField);
$required = new RequiredFields(array('Grade'));
$form = new Form($this, 'FeedbackForm', $fields, $actions, $required);