Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6008519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:50:10+00:00 2026-05-23T01:50:10+00:00

I need to add a behavior to ModalWindow such that when a user clicks

  • 0

I need to add a behavior to ModalWindow such that when a user clicks outside of the modal, if a certain condition is met (checked server-side in my respond() method), the modal is dismissed.

I tried implementing something based on this answer. The problem is that I can’t attach a click listener to the modal window div because it’s not added to the DOM until the modal is shown (the example attaches a keyup to the document itself.)

I thought of extending ModalWindow and adding the JS via getShowJavascript(), but then I don’t have any means to connect it to an AbstractDefaultAjaxBehavior.respond() method for the test.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T01:50:11+00:00Added an answer on May 23, 2026 at 1:50 am

    I solved this by adding the behavior not to the modal, but rather to the widget I add to the modal via ModalWindow.setContent(). When my widget is added to the modal, the mask div is present in the DOM, and I can then successfully attach a click handler.

    To wit:

    public static class CloseModalOnOutsideClickBehavior extends AbstractDefaultAjaxBehavior
    {
        private final ModalWindow modal;
    
        public CloseModalOnOutsideClickBehavior(ModalWindow modal)
        {
            this.modal = modal;
        }
    
        @Override
        protected void respond(AjaxRequestTarget target)
        {
            if (myConditionIsMet()) modal.close(target);
        }
    
        @Override
        public void renderHead(IHeaderResponse response)
        {
            response.renderJavascriptReference("http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js");
            response.renderJavascript("" +
                    "$(document).ready(function() {\n" +
                    "  $('div.wicket-mask-dark').bind('click', function(evt) {\n" +
                            getCallbackScript() + "\n" +
                    "        evt.preventDefault();\n" +
                    "  });\n" +
                    "});", "closeModal");
        }
    }
    

    Note that I’m somewhat precariously depending on the modal window’s mask having a class named “wicket-mask-dark”; this may not be the case if you alter the CSS settings used by ModalWindow.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to add a class above or below to my input element depending
I need to add two irregular time series (covering business days). I have two
I need to add a Hover event to all the elements on the page,
Is it possible to add an item in C# project that is similar to
Let's say, for the sake of argument, that I have 30 asp.net web applications
I have a query that picks out a specific row/column from a large database.
I am working on a large application and am adding some drag/drop functionality to
I've got two questions/issues regarding the AspxPivotGrid . When I use the customization window
I'm using FlexJSON(but I'm open to other libraries) and I want to manually build

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.