Help with implementing aurelia-validation (for pay)


I have a fairly simple questionnaire that contains radio button groups that are required. I’d like help implementing aurelia-validation into the process.

Please and thanks,

Hi Jason, on Google I found a demo containing a required radio button group.

Demo radio button group validation

Hi there,

I found this example but still couldn’t get it integrated with my setup. I’ve got custom elements like this:

<input type=radio

I’d pay if you were able to make it happen.



Please use the code syntax to let us be able to see your actual code :wink: --> in the editor toolbar </>

This is a code block

Here it goes:


<h2>Answer Questions</h2>
<questions questions.bind="questions""allQuestionsAnswered(items)"> . 


<form submit.delegate="submit()">
<div repeat.for="question of questions | groupBy:''">
  <question q.bind="question"></question>


export class QuestionsCustomElement {
  @bindable({ defaultBindingMode: bindingMode.twoWay }) public questions!: [null];
  public validationValid: boolean = false;
  public validationObject: any = {};
  private validationController: ValidationController;

 constructor(validationControllerFactory: ValidationControllerFactory) {
    this.logger = LogManager.getLogger('Questions Custom Element');
    this.validationController = validationControllerFactory.createForCurrentScope();
    this.validationController.validateTrigger = validateTrigger.manual;

 public questionsChanged(newValue, oldValue): void {'Questions custom element items changed:', newValue, oldValue);

 public submit(): void {
     const items = this.questions;'Preparing to submit questions', items);

    this.validationController.validate().then(r => {'Validation result', r.valid, r);


   <div class="row">
    <div class="col-xs-12 col-md-8">
         <i class="text-primary mr-2 align-middle" 
         class.bind="getClassForCategory(" aria-hidden="true"></i>
       <p class="lead text-left text-muted mb-4">${question.values[0].area.description}</p>

<div class="row">
  <div class="col-xs-12">
       <li repeat.for="error of validationController.errors">${error.message}</li>
     <fieldset class="mb-4" repeat.for="question of question.values">
         <div class="row">
           <div class="col-sm-8 text-left">
              <p class="lead text-left">

        <!--<radio-select items-source.bind="question.answerChoices" value.bind="question.selectedAnswer & validate" aria-labelledby="color1"

        <!--<input type="text" value.bind="question.selectedAnswer & validate" class="required-message" />-->

        <div class="error-message" style="visibility: hidden">A choice is required.</div>
           <div class="radio" repeat.for="choice of question.answerChoices">
              <label for="${choice}-${}">
                  <input type="radio" name.bind="" id="${choice}-${}" value.bind="choice"
              checked.bind="question.selectedAnswer" role="group" required data-error- 
        <!--<strong>Selected: ${question.selectedAnswer}</strong>-->
      <div class="col-sm-4 text-left border-default border-left">
        <div class="text-muted" innerhtml.bind="question.example"></div>


import './question.element.scss';
import { autoinject, bindable, bindingMode } from 'aurelia-framework';
import { LogManager, Logger } from './../../../services/logger.service';
import {
    validateTrigger, ValidationController, ValidationControllerFactory, ValidationRules
} from 'aurelia-validation';

export class QuestionCustomElement {
    @bindable({ defaultBindingMode: bindingMode.twoWay }) public q!: [null];
    public question: Question = new Question();

    public answerChoices = ['Yes', 'No', 'I Don\'t Know'];
    public validationValid: boolean = false;
   public validationObject: any = {};

   private logger: Logger;
   private validationController: ValidationController;
   private controls = [];

  constructor(validationControllerFactory: ValidationControllerFactory) {
      this.logger = LogManager.getLogger('Question Custom Element');

      this.validationController = validationControllerFactory.createForCurrentScope();
      this.validationController.validateTrigger = validateTrigger.manual;

public qChanged(newValue, oldValue): void {'Question custom element items changed:', newValue, oldValue);

    if (newValue) {
       // console.log('newValue', newValue); =;
       this.question.values = [];

       newValue.values.forEach(item => {
          // console.log('item', item);
         const questionItem = new QuestionItem(); =;
         questionItem.answerChoices = item.answerChoices;
         questionItem.text = item.text;
        questionItem.example = item.example;
        questionItem.selectedAnswer = '';

     /* any) => {
        bind: question.selectedAnswer,
        validation: '.required()'
        } as never);
      }); */

      // this.setupValidator();

public setupValidator(): void {
    const rules = []; any) => {'control:', control, control.validation);

       if (control.validation) {
 'control:', control, control.validation, control.bind);
           if (control.validation) {
              if (control.validation.match(/\.required\(\)/)) { 
                rules.push(ValidationRules.ensure(control.bind).required().rules[0] as never); }

        this.validationController.addObject(this.validationObject, rules);

export class Question {
    public group: string = '';
    public values: QuestionItem[] = [];

export class QuestionItem {
    public id = 0;
    public text: string = '';
    public answerChoices: any[] = [];
    public selectedAnswer: string = '';
    public example: string = '';


Unfortunately the formatting is still not perfect. Next time you need to prefix every line with 4 spaces to use the code block formatting. That being said, let’s try as it is.

What I noticed, is that you bind the value “choice” to the same object as in the repeat.for. That is not corresponding to the example in the Guide. In your example you would need to bind it to question.selectedAnswer

Is the value changed as you expect? Perhaps use the Chrome Aurelia Inspector or some console.log to check that first.

Next thing. Is the element actually being validated? I was not able to find the this.validationController.validate() function, though I might have missed it.

I was hoping to be able to provide you the code (easy to get running) and then we could post the resolution here. Sorry for the formatting woes.

Sorry, I’m not able to fully debug and change for you. With my questions I tried to a) make your question more clear for anyone reading the issue and b) hint you into the proper direction to sort things out.