In EWL, how do I show custom validation content at an arbitrary place in the page?

29 views Asked by At

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?

1

There are 1 answers

2
William Gross On

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.