How to prevent form closing if user clicks outside the form

How to prevent form closing if user clicks outside the form

phpkidphpkid Posts: 10Questions: 2Answers: 0
edited August 2012 in Editor
Sorry if there is a simple answer to this but I have looked through the documentation/examples without success so far.

In all the examples if the user clicks outside the form then the form simply closes and all data entered is lost. Which would be a shame in my application as my form is very big!

Is there a way of changing the behaviour of the form so it only closes if the create/update or cancel buttons are pressed?

Thanks in advance

Alec

Replies

  • allanallan Posts: 61,650Questions: 1Answers: 10,094 Site admin
    Hi Alec,

    The easiest way, at present, to do this is to simply remove the following code block from the 'lightbox' display controller:

    [code]
    $(self._dom.background).click( function (e) {
    self._dte.close('background');
    } );
    [/code]

    The other option is to unbind the click event that Editor adds to the background element.

    I will look at having a way to cancel the closing using the onClose event in future, which would be a much cleaner way of doing this.

    Regards,
    Allan
  • phpkidphpkid Posts: 10Questions: 2Answers: 0
    Hi Allan,

    Many thanks for the quick reply. Rather than patching your code I have decided to try switching off the two click event handlers that seem to cause this behaviour:

    [code]
    "events" : {
    "onInitComplete" : function (json, data){
    $('.DTED_Lightbox_Background').off('click');
    $('.DTED_Lightbox_Content_Wrapper').off('click');
    }
    [/code]

    If I have any problem with this approach I will revert to your other suggestion.

    It would be good to have this as a standard option in future releases. In fact, since the Lightbox_background is already opaque it may be worth thinking about making this the default behaviour.

    Thanks again for the quick response.

    p.s. DataTables and Editor are both awesome tools. I will be buying my licenced copy today.


    Alec
  • allanallan Posts: 61,650Questions: 1Answers: 10,094 Site admin
    Hi Alec,

    Delighted to hear you are enjoying using Editor and DataTables :-).

    Your 'off' approach looks idea to me - until a proper solution is implemented (probably preventDefault or returning false from an onClose handler).

    I think there are three basic cases which need to be coped with:

    1. Closing automatically like it currently does
    2. Not closing
    3. Asking for confirmation before closing.

    Ensuing that all three options can easily be achieved is what I'll be aiming for here.

    Regards,
    Allan
This discussion has been closed.