Skip to content

Commit

Permalink
✨ Make Router#applyDirective() also set the route method if possible
Browse files Browse the repository at this point in the history
  • Loading branch information
skerit committed Feb 25, 2024
1 parent 13c8f21 commit 1b7b654
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* Fix `Loopback` conduits not having some GET parameters available
* Add more information to enums (icons, color, ...)
* Fix helper `Router#routeUrl()` throwing an error when the parameters arg is null
* Make `Router#applyDirective()` also set the route method if possible

## 1.4.0-alpha.2 (2024-02-19)

Expand Down
9 changes: 8 additions & 1 deletion lib/app/helper/router_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ Router.setMethod(function isLocalUrl(url) {
*
* @author Jelle De Loecker <[email protected]>
* @since 1.1.0
* @version 1.3.1
* @version 1.4.0
*
* @param {Element} element The element to apply to
* @param {string} name The route name
Expand Down Expand Up @@ -225,13 +225,16 @@ Router.setMethod(function applyDirective(element, name, options) {
disable_ajax = true;
}

let method_attribute = false;

if (element.role == 'link') {
attribute_name = 'href';
} else {

switch (element.nodeName) {
case 'FORM':
attribute_name = 'action';
method_attribute = 'method';
break;

case 'AREA':
Expand Down Expand Up @@ -260,6 +263,10 @@ Router.setMethod(function applyDirective(element, name, options) {
}
}

if (method_attribute && config.methods?.[0]) {
element.setAttribute(method_attribute, config.methods[0]);
}

if (disable_ajax) {
element.setAttribute('data-he-link', 'false');
}
Expand Down

0 comments on commit 1b7b654

Please sign in to comment.