Dialog - Prevent close #232

Closed
mikeburgh opened this Issue Nov 30, 2016 · 1 comment

Projects

None yet

2 participants

@mikeburgh

Adding a way (possibly returning false in the handler) that prevents a dialog from closing.

Idea is so you can validate the form input and if it's not valid show the error and prevent the dialog from being closed.

@rstoenescu rstoenescu added this to the v0.10 milestone Nov 30, 2016
@rstoenescu rstoenescu added the proposal label Nov 30, 2016
@rstoenescu rstoenescu modified the milestone: v0.11, v0.10, v0.12 Dec 16, 2016
@rstoenescu rstoenescu modified the milestone: v0.12, v0.13 Dec 30, 2016
@rstoenescu
Collaborator

You can specify preventClose: true for a Dialog button. In this case the handler() will receive a second parameter which is a function that can close the Dialog.

So if you use preventClose then it's going to be your duty to close the dialog yourself by calling that second param function.

Example:

Dialog.create({
  title: 'Prevent Close',
  message: 'Having "Prevent" checkbox ticked and then hitting "Try to Close" button will prevent the dialog from closing.',
  form: {
    prevent: {
      type: 'checkbox',
      items: [
        {label: 'Prevent dialog close', value: 'prevent', model: true}
      ]
    }
  },
  buttons: [
    {
      label: 'Try to Close',
      preventClose: true,
      handler (data, close) {
        if (!data.prevent.length) {
          close(() => {
            Toast.create(`Finally. It's closed now.`)
          })
          return
        }
        Toast.create('Untick "Prevent" checkbox to be able to close the Dialog.')
      }
    }
  ]
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment