2

I have a page that collects an email address, and upon submission of the form I see if that email exists. If it does, the user can't create the entity. Instead of showing a normal validation error status message, I would like to show a nice paragraph explaining the situation with a couple links.

I've tried creating the paragraph and hiding it with either .visible = false or display:none, and then making it visible inside the method passed to AddTopValidationMethod. This does not work.

I know I can have HTML status messages but 1) I don't think this would be as good and 2) I wouldn't be able to build my links using EwfLink - I'd have to hand-write an anchor tag.

What's the best solution here?

William Gross
  • 2,083
  • 2
  • 17
  • 35
Greg Smalter
  • 6,571
  • 9
  • 42
  • 63

1 Answers1

3

Try this:

// Add the form item to the page.
var validationFailed = false;
myPanel.AddControlsReturnThis( myMod.GetEmailAddressTextFormItem( false, validationErrorNotifier: () => validationFailed = true, validationList: myPostBack ).ToControl() );

// Add the email-address-exists error placeholder to the page.
myPanel.AddControlsReturnThis(
  new ModificationErrorPlaceholder(
    new Validation(
      ( pbv, validator ) => {
        if( validationFailed )
          return;
        if( emailAddressExists( myMod.EmailAddress ) )
          validator.NoteErrorAndAddMessage( "The user will never see this." );
      },
      myPostBack ),
    errors => {
      if( !errors.Any() )
        return Enumerable.Empty<Control>();

      // Use any controls you want here!
      var link = EwfLink.Create( MyDestinationPage.GetInfo(), new TextActionControlStyle( "has a link" ) );
      return new Paragraph( new Control[] { "This sentence ".GetLiteralControl(), link, " in it.".GetLiteralControl() } ).ToSingleElementArray();
    } ) );

And if you want your explanatory paragraph to be above the email address form item, add its validation to a BasicValidationList, which you can add to your post-back object after you've created the form item.

William Gross
  • 2,083
  • 2
  • 17
  • 35
  • I think you'd want to use NoteError() instead of NoteErrorAndAddMessage( "The user will never see this." ). – Greg Smalter Sep 09 '14 at 19:56
  • @GregSmalter, I don't think that will work. Notice that the logic in the `controlGetter` function (second argument to `ModificationErrorPlaceholder`) is based on an error message collection, not on the `Validator`. – William Gross Sep 10 '14 at 14:33