简体   繁体   中英

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

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM