-
Notifications
You must be signed in to change notification settings - Fork 19
proof of concept demo with iron-form #12
base: master
Are you sure you want to change the base?
Changes from 1 commit
07927d1
f1a04f8
eb89618
f85d80c
1bb4083
a93bfb9
1c7f951
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ | |
license that can be found in the LICENSE file. | ||
--> | ||
<link rel="import" href="../polymer/polymer.html"> | ||
<link rel="import" href="../iron-form-element-behavior/iron-form-element-behavior.html"> | ||
<link rel="import" href="../iron-validatable-behavior/iron-validatable-behavior.html"> | ||
|
||
<!-- | ||
Polymer element for Google reCAPTCHA | ||
|
@@ -26,6 +28,9 @@ | |
:host { | ||
display: block; | ||
} | ||
:host.invalid { | ||
outline: 1px solid red; | ||
} | ||
</style> | ||
<template><content></content></template> | ||
</dom-module> | ||
|
@@ -43,6 +48,18 @@ | |
_containerId:'', | ||
_captchaId:'', | ||
|
||
_invalid: true, | ||
|
||
behaviors: [ | ||
Polymer.IronFormElementBehavior, | ||
Polymer.IronValidatableBehavior | ||
], | ||
|
||
_getValidity: function () { | ||
this.toggleClass('invalid', this._invalid); | ||
return !this._invalid; | ||
}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
a google-recaptcha element's |
||
|
||
properties: { | ||
/** | ||
* The total time (in milliseconds) to wait for API loading | ||
|
@@ -95,10 +112,10 @@ | |
}, | ||
|
||
observers: [ | ||
'_validate(theme, type, timeout)' | ||
'_validateAttrs(theme, type, timeout)' | ||
], | ||
|
||
_validate:function () { | ||
_validateAttrs: function () { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Calling this |
||
if(this.theme!='dark' && this.theme!='light'){ | ||
this.theme='light'; | ||
} | ||
|
@@ -217,6 +234,8 @@ | |
* @param {String} response response to store | ||
*/ | ||
_responseHandler: function (response) { | ||
this._invalid = false; | ||
this.toggleClass('invalid', this._invalid); | ||
this.response=response; | ||
this.fire('captcha-response',{response:response}); | ||
}, | ||
|
@@ -232,6 +251,8 @@ | |
* The `expiredHandler` method fires the captcha-expired event. | ||
*/ | ||
_expiredHandler: function () { | ||
this._invalid = true; | ||
this.toggleClass('invalid', this._invalid); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if we should be modifying the dom imperatively like this rather than achieving this via a declarative binding, but just wanted to get something working. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (i.e. |
||
this.fire('captcha-expired'); | ||
} | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This just puts a red box around the google-recaptcha element when it has the "invalid" class. Ideally we would be able to toggle the rc-anchor-error class on the .rc-anchor element inside the iframe (to get the checkbox inside the captcha to be rendered in red), but not sure if we can access that element due to cross-origin policy.