What is the purpose of the validationErrorNotifier in generated FormItems?

35 views Asked by At

I've got FormItems getting generated against the tables in my SQL database. I'm looking through the generated FormItems for my TableModification and I'm noticing an interesting optional parameter Action validationErrorNotifier.

How does one use this parameter and what benefits does it bring?

1

There are 1 answers

0
William Gross On BEST ANSWER

Let's say you have a form with two phone number fields. And let's say you want to have a subsequent Validation that produces an error if the two phone numbers don't have matching area codes. You could use the validationErrorNotifier parameter in conjunction with a bool to make sure you only execute the subsequent Validation when both phone numbers are valid:

var phonesInvalid = false;
var stack = ControlStack.CreateWithControls(
    myTableMod.GetPhone1FormItem( ..., validationErrorNotifier: () => phonesInvalid = true, validationList: myDataMod ).ToControl(),
    myTableMod.GetPhone2FormItem( ..., validationErrorNotifier: () => phonesInvalid = true, validationList: myDataMod ).ToControl()
);
formItemBlock.Add( FormItem.Create(
    "Phone Numbers",
    stack,
    validationGetter: control => new Validation(
        ( pbv, validator ) => {
            if( !phonesInvalid && myTableMod.Phone1.AreaCode != myTableMod.Phone2.AreaCode )
                validator.NoteErrorAndAddMessage( "Area codes must match." );
        },
        myDataMod
    )
) );