CallbackValidationRole – example – checkbox

Here is a CallbackValidationRole example form that validates whether a checkbox is checked:

https://forms.neurodot-consulting.com/HTML5/?formid=ffe3f0e9-46db-4dd2-9bdd-3f8940161696&version=null

Path on our test web: Root-> Mike’s World -> Customers (Mike) -> CallbackValidation_CheckBox

The form maps eForm‘s event Loaded:

Code:

using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;
using System.Xml.Linq;
using Neurodot.Forms.Controls;
using Neurodot.Forms.CustomControls.RadioGroup;
using Neurodot.Forms.Render;
using Neurodot.Forms.Render.Interfaces;

public static partial class FormCodeClass
{
    // To find controls in the current visual tree (i.e. the form) use static methods:
    // object ThisForm.FindElement(string elementName); or 
    // T ThisForm.FindElement<T>(string elementName);

    static CheckBox _checkBox = ThisForm.FindElement<CheckBox>("CheckBoxConfirm");


    public static void Loaded(object sender, System.Windows.RoutedEventArgs e)
    {
        var role = new CallbackValidationRole("$CheckValidationMessage") { Callback = ValidateConfirmCheckBox };
        ThisForm.RegisterValidationRole(_checkBox, role);
    }
    
    // Validates if the checkbox is checked.
    // Returns true if the checkbox is checked (valid); otherwise, false (invalid).
    private static bool ValidateConfirmCheckBox()
    {
        return (_checkBox.IsChecked == true);
    }
}