medusa-ui/medusa

Rewrite: click event

Closed this issue · 3 comments

We will need a custom tag for a click event.

This wraps the following function:
onclick="_M.doAction(_wrapping_fragment_, 'myAction()')"

_wrapping_fragment is filled up by the time of rendering. If there is no wrapping fragment, it's null.

In Medusa 0.x this worked like m:change="increaseCounter(1, 'ABC')

The goal is to be able to reference a method on the controller side directly.

  • Should be able to refer to a method without parameter doAction()
  • Should be able to add parameters to the method doAction(1, 'ABC')
  • Should be able to refer to other values (ie if I click, send the value of an input field as parameter); I have no requirement on how to refer to this, my suggestion would be doAction(#mySearchField, 123)
  • A common pattern is to disable a button after button press until the message is resolved, to prevent double-clicking to fire an event twice. Perhaps this should be an option with this default on?

Reworked in Rewrite 1.0.0 click and change event #274

example

<input id="elm" type="text">
<button m:click="someAction(:{#elm})">some action</button>

will result in

<input id="elm" type="text">some actual text</input>
<button onclick="_M.doAction(null, `someAction('${document.querySelector('#elm').value}')`)'">some action</button>

remark:
PR does not include disabling the button to avoid a second click.

  • This should be done on the JS side?
  • Do we really want this? Current usages of m:click is not a form-submit that takes you to another page. I think this is more related to issue #248
  • Can't this be done with Thymeleaf via th:disable ?

Re: disable button. I agree that this actually probably makes more sense with form submits. I've moved it there.

Ref PR #274