Skip to content

Commit 66166a1

Browse files
committed
closes primefaces#3446 - support invisible recaptchas
1 parent a08a2c6 commit 66166a1

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/main/java/org/primefaces/component/captcha/CaptchaRenderer.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ protected void encodeMarkup(FacesContext context, Captcha captcha, String public
6565
captcha.setRequired(true);
6666
writer.startElement("div", null);
6767
writer.writeAttribute("id", clientId, "id");
68+
69+
if (captcha.getSize() != null && "invisible".equals(captcha.getSize())) {
70+
writer.writeAttribute("class", "g-recaptcha", null);
71+
writer.writeAttribute("data-sitekey", publicKey, null);
72+
writer.writeAttribute("data-size", "invisible", null);
73+
}
6874

6975
renderDynamicPassThruAttributes(context, captcha);
7076

src/main/resources/META-INF/resources/primefaces/captcha/captcha.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ PrimeFaces.widget.Captcha = PrimeFaces.widget.BaseWidget.extend({
1414

1515
$(document.body).append('<script src="https://www.google.com/recaptcha/api.js?onload=' + this.cfg.widgetVar + '_initCallback&render=explicit&hl='
1616
+ this.cfg.language +'" async defer>');
17+
1718
},
1819

1920
render: function() {
@@ -26,6 +27,10 @@ PrimeFaces.widget.Captcha = PrimeFaces.widget.BaseWidget.extend({
2627
'expired-callback': $this.cfg.expired,
2728
'size': this.cfg.size
2829
});
30+
31+
if (this.cfg.size === 'invisible') {
32+
grecaptcha.execute();
33+
}
2934

3035
window[this.cfg.widgetVar + '_initCallback'] = undefined;
3136
}

0 commit comments

Comments
 (0)