1

I am creating a component,

controllers
    theatercontroller
    facilitycontroller
Models
    theater
    facility
view
    theater
    facility

What I want is I want to add a new facility from the theater view by clicking a button and opening a modal window. I have tried but didn't work. I studied some components but it is difficult for someone like me to understand it. Please I need a simple example and a explanation to understand it.

2 Answers 2

14

It doesn't have to be anywhere near that complicated. Many templates turn the modal behavior on already, but if they don't all you need to do is add this to the head -

<?php JHTML::_('behavior.modal'); ?>

Then add this to any links you want to open in a modal window -

class="modal"

Everything else is optional.

3
  • I have used it to your way It loads fine but when I saved it it will load the view with menus and toolbar. I don't know how to prevent it.
    – Sara
    Dec 30, 2011 at 10:34
  • What are you loading in the modal window and what are you saving? Jan 2, 2012 at 17:29
  • 4
    You need to add &tmpl=component to the url you are loading in the modal window May 22, 2013 at 17:55
5

You can use this function to get a modal button

static public function getModalButtonObject($name,$text,$link,$width=750,$height=480)
{
    JHTML::_('behavior.modal', "a.{$name}");  // load the modal behavior for the name u given
        $buttonMap = new JObject();   // create an Jobject which will contain some data, it is similar like stdClass object
        $buttonMap->set('modal', true);
        $buttonMap->set('text', $text );
        $buttonMap->set('name', 'image');
        $buttonMap->set('modalname', $name);
        $buttonMap->set('options', "{handler: 'iframe', size: {x: ".$width.", y: ".$height."}}");
        $buttonMap->set('link', $link);
        return $buttonMap;
}

And HTML can be written as

<a id="<?php echo $buttonMap->modalname; ?>" class="<?php echo $buttonMap->modalname; ?>" title="<?php echo $buttonMap->text; ?>" href="<?php echo $buttonMap->link; ?>" rel="<?php echo $buttonMap->options; ?>"><?php echo $buttonMap->text; ?></a>
2
  • Thanks for you code. I am new to this so can you please explain what is happening there and how to use it.
    – Sara
    Dec 23, 2011 at 7:22
  • 1
    There is nothing special in it. I have just loaded a modal behavior, for the button and created a JObject which can be used in HTML.
    – Gaurav
    Dec 23, 2011 at 7:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.