Last active
December 19, 2023 09:11
-
-
Save cyberfly/60fabe5bcc146a3aacd0f07f56e8ac27 to your computer and use it in GitHub Desktop.
Add validation to hx-trigger. If validate false, hx-post is not trigger `hx-trigger="submit[!isFieldEmpty('#seed_keyword')]`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form | |
id="keyword_suggestions_form" | |
hx-post="/api/v1/keywords" | |
hx-target="#keywords_container" | |
hx-indicator="#loader_container" | |
hx-on:htmx:before-request="emptyDiv('#keywords_container')" | |
hx-trigger="submit[!isFieldEmpty('#seed_keyword')], submitKeywordSearch from:body" | |
> | |
<button type="submit">Search</button> | |
</form> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.isEmpty = function isEmpty(variable) { | |
variable = $.trim(variable); | |
return variable === undefined || variable === null || variable === ""; | |
}; | |
window.isFieldEmpty = function isFieldEmpty(id) { | |
let value = $(id).val(); | |
return isEmpty(value); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment