PROPERTIES
Captcha
Use the reCAPTCHA element to verify that site visitors are human before allowing them to perform restricted operations such as data submission, login, or accessing private content.
Typical CAPTCHA Validation Lifecycle
Important: To ensure complete protection, you must include backend authorization as a mandatory step of the CAPTCHA validation lifecycle.
The following outlines a typical CAPTCHA validation lifecycle:
- A button or another clickable element that triggers a submit, login, or another restricted operation is disabled, pending CAPTCHA verification.
- A site visitor completes the CAPTCHA challenge. One of the following occurs:
- Verification: The CAPTCHA is verified. A
token
is generated. TheonVerified()
event indicates a successful CAPTCHA challenge completion. Use theonVerified()
event handler to enable the disabled clickable element. - Error: The reCAPTCHA element loses connection with the CAPTCHA provider. You can use the
onError()
event handler to instruct the visitor to try again later. Return to Step 1.
- Verification: The CAPTCHA is verified. A
- The clickable element is enabled. One of the following occurs:
- Click: The site visitor clicks the clickable element, triggering a backend function that calls
authorize()
with the generatedtoken
. - Timeout: The site visitor did not click the submit button within 120 seconds of token generation, causing the token to expire. When timeout occurs, the reCAPTCHA element automatically resets and displays a message asking the site visitor to redo the challenge. Use the
onTimeout()
event handler to disable the clickable trigger. Return to Step 1.
- Click: The site visitor clicks the clickable element, triggering a backend function that calls
authorize()
checks whether the token is valid. One of the following occurs:
For more information on working with your reCAPTCHA element, click here.
Note
The reCAPTCHA element does not offer protection for data submission performed via a dataset. To protect data submission with CAPTCHA, use code to perform the data operation (for example,insert()
or save()
).Table of Contents
FUNCTIONS
collapsed
property to true
.collapsed
property to false
.Hides the element and sets its hidden
property
to true
, using an effect if specified.
Adds an event handler that runs when the mouse pointer is moved onto the element.
Adds an event handler that runs when the mouse pointer is moved off of the element.
Adds an event handler that runs when an element is displayed in the viewable part of the current window.
Adds an event handler that runs when an element is no longer displayed in the viewable part of the current window.
Shows the element and sets its hidden
property
to false
, using an effect if specified.
collapsed
Description
If collapsed
is true
, the element is not displayed on the page under
any circumstances. A collapsed element, unlike a
hidden
element, does not take up any
space on the page. When collapsed, elements positioned within 70 pixels
below the collapsed element and each other move up to take the
collapsed element's place where possible. The elements that move up
maintain their positions relative to one another.
If collapsed
is false
, the element may be displayed on the page.
Elements that moved up to take the collapsed element's place on the
page are moved back down.
However, an expanded element (an element whose collapsed
property is
false
) is still not displayed if:
- It is hidden.
- Its parent element is hidden or collapsed.
- It is a slide in a Slideshow which is currently not being displayed.
Even if the element is not be displayed due to the conditions
mentioned above, if its collapsed
property is false
, it's
displayed when the conditions no longer apply.
To set the collapsed
property on an element, use the element's
collapse()
and expand()
functions.
If you select Collapsed on load in the element's Properties panel
in the Editor, the collapsed
property is set to true
when the page loads.
See Also
Syntax
get collapsed(): boolean
MIXED IN FROM
Examples
Get an element's collapsed status
let isCollapsed = $w("#myElement").collapsed; // false
Toggle an element's collapsed state
if( $w("#myElement").collapsed ) {
$w("#myElement").expand();
}
else {
$w("#myElement").collapse();
}
global
Description
If global
is true
, the element appears on all pages.
If global
is false
, the element only appears on the current page.
Syntax
get global(): boolean
MIXED IN FROM
Examples
Get whether an element is displayed on all pages
let isGlobal = $w("#myElement").global; // false
hidden
Description
If hidden
is true
, the element is not displayed on the page under
any circumstances. A hidden element, unlike a
collapsed
element, continues to
take up the same space on the page as it did when it was visible.
If hidden
is false
, the element may be displayed on the page.
However, an element whose hidden
property is false
is still not
displayed if:
- It is collapsed.
- Its parent element is hidden or collapsed.
- It is a slide in a Slideshow which is currently not being displayed.
Even if the element is not displayed due to the conditions
mentioned above, if its hidden
property is set to false
, it's
displayed when the conditions no longer apply.
To determine if the element is actually visible, use the
isVisible
property.
To set the hidden
property on an element, use the element's
hide()
or show()
functions.
If you select Hidden on load in the element's Properties panel
in the Editor, the hidden
property is set to true
when the page loads.
Note
An element's hidden
property is not the same as its
isVisible property. The hidden
property
indicates whether the element should be displayed, while isVisible
indicates if it is actually displayed.
See Also
hide( ), show( ), collapse( ), expand( ), collapsed, rendered
Syntax
get hidden(): boolean
MIXED IN FROM
Examples
Get an element's hidden status
let isHidden = $w("#myElement").hidden; // false
Toggle an element's hidden state
if( $w("#myElement").hidden ) {
$w("#myElement").show();
}
else {
$w("#myElement").hide();
}
id
Description
The ID is the element's unique identifier. It is used when selecting
elements using the $w()
function.
An element's id
is set in the Editor using the Properties panel.
Syntax
get id(): string
MIXED IN FROM
Examples
Get the ID
let myId = $w("#myElement").id; // "myElement"
isVisible
Description
If isVisible
is true
, the element is displayed on the page.
If isVisible
is false
, the element is not displayed on the page.
The value of the isVisible
property is calculated based on the
hidden
, collapsed
, and rendered
properties of the element and all of its ancestors. It is true
only if the conditions exist in the element's property values and the
property values of its ancestors such that the element is actually
displayed on the page.
Note
An element's isVisible
property is not the same as its
hidden property. The isVisible
property
indicates whether the element is actually displayed, while hidden
indicates if it should be displayed.
The isVisible
property of an element remains true
even if
another element completely covers it so that a user cannot see it.
See Also
Syntax
get isVisible(): boolean
MIXED IN FROM
Examples
Get whether an element is visible
let isVisible = $w("#myElement").isVisible; // true
parent
Description
See Also
Syntax
get parent(): Node
MIXED IN FROM
Examples
Get the parent element and the parent's ID
let parentElement = $w("#myElement").parent;
let parentId = parentElement.id; // "page1"
Syntax
get rendered(): boolean
MIXED IN FROM
Examples
Get an element's rendered status
let isRendered = $w("#myElement").rendered; // true
token
Description
When a site visitor successfully completes a CAPTCHA challenge, a token
is generated. The token is used for backend authorization.
Prior to completing the CAPTCHA challenge and following timeout, the token returns undefined
.
Syntax
get token(): string
Examples
Get the token of the verified reCAPTCHA element
let myToken = $w("#myCaptcha").token;
// "1ABCDeFG23hijKlmn4...OPQ5r6stuvWXy"
Full CAPTCHA lifecycle scenario
This example demonstrates how to use reCAPTCHA to protect a data insertion. We use a text input for the data, a reCAPTCHA element, and a submit button. The submit button is disabled until the CAPTCHA is verified and a token is generated. Clicking the submit button triggers backend authorization of the token. If authorization is successful, the data is inserted into the collection.
/************************************
* backend code - submitHandler.jsw *
************************************/
import wixCaptcha from 'wix-captcha-backend';
import wixData from 'wix-data';
// Authorize token and insert data
export function processSubmission(submitRequestData) {
return wixCaptcha.authorize(submitRequestData.token)
.then( () => {
return wixData.insert("MyCollection", submitRequestData.data)
.then( () => ({"type": "success"}))
.catch( (error) => ({"type": "insertion error", "message": "Error: collection insertion failed: " + error}));
})
.catch( (error) => ({"type": "authorization error", "message": "Error: reCAPTCHA authorization failed: " + error}));
}
/********************
* client-side code *
********************/
import {processSubmission} from 'backend/submitHandler';
$w.onReady(function () {
// When user clicks submit button
$w("#submitDataButton").onClick(() => {
let submitRequestData = {
token: $w("#myCaptcha").token,
data: $w("#myInput").value,
}
processSubmission(submitRequestData) // Call backend function
.then( (response) => {
// Display a different message depending on response from backend function
switch(response.type){
case "success":
$w("#messageText").text = "Data successfully submitted";
break;
case "authorization error":
$w("#messageText").text = "CAPTCHA authorization failed. Redo the CAPTCHA challenge.";
break;
case "insertion error":
$w("#messageText").text = "Database error. Redo the CAPTCHA challenge.";
break;
}
$w("#myCaptcha").reset();
$w("#submitDataButton").disable();
$w("#messageText").show();
});
});
// Error handler
$w("#myCaptcha").onError(() => {
$w("#messageText").text = "The reCAPTCHA element lost connection with the CAPTCHA provider. Try again later.";
$w("#messageText").show()
.then(() => {
$w("#messageText").hide("fade", {"delay": 10000});
} );
})
// Verification handler
$w("#myCaptcha").onVerified(() => {
$w("#submitDataButton").enable();
$w("#messageText").hide();
})
// Timeout handler
$w("#myCaptcha").onTimeout(() => {
$w("#submitDataButton").disable();
$w("#messageText").text = "The CAPTCHA has timed out. Please redo the CAPTCHA challenge.";
$w("#messageText").show();
});
});
Examples
Get the element's type
let myType = $w("#myElement").type; // "$w.Type"
blur( )
Description
The blur()
function removes focus from the element and fires a blur
event.
The blur
event handlers set on this element by the onBlur( )
function or in the Editor are called.
Removing focus through a call to this function is equivalent to a user clicking on another element or tabbing out of the element manually.
If blur() is called on an element that is not in focus, it has no effect.
The element in focus remains in focus and the onBlur
event handlers
are not called.
See Also
Syntax
function blur(): void
MIXED IN FROM
Examples
Remove focus from an element
$w("#myElement").blur();
collapse( )
collapsed
property to true
.Description
See Also
Syntax
function collapse(): Promise<void>
collapsed
property has been set to true
.MIXED IN FROM
Examples
Collapse an element
$w("#myElement").collapse();
Collapse an element and log a message when done
$w("#myElement").collapse()
.then( () => {
console.log("Done with collapse");
} );
Toggle an element's collapsed state
if( $w("#myElement").collapsed ) {
$w("#myElement").expand();
}
else {
$w("#myElement").collapse();
}
expand( )
collapsed
property to false
.Description
See Also
Syntax
function expand(): Promise<void>
collapsed
property has been set to false
.MIXED IN FROM
Examples
Expand an element
$w("#myElement").expand();
Expand an element and log a message when done
$w("#myElement").expand()
.then( () => {
console.log("Done with expand");
} );
Toggle an element's collapsed state
if( $w("#myElement").collapsed ) {
$w("#myElement").expand();
}
else {
$w("#myElement").collapse();
}
focus( )
Description
The focus()
function places focus on the element and fires a focus
event.
The focus
event handlers set on this element by the onFocus( )
function or in the Editor are called.
Receiving focus through a call to this function is equivalent to a user clicking on or tabbing to the element manually.
See Also
Syntax
function focus(): void
MIXED IN FROM
Examples
Place focus on an element
$w("#myElement").focus();
hide( )
Hides the element and sets its hidden
property
to true
, using an effect if specified.
Description
The hide()
function hides the element and returns a Promise that is
resolved when the effect is complete and the element's hidden
property has been set to true
.
To learn about the behavior of a hidden element,
see the hidden
property.
You can optionally apply an effect when hiding the element by providing
an effectName
value. You can also customize the effect by providing the
optional effectOptions
object.
Effects:
You can also hide an element when the page loads by using the Properties panel in the Editor.
See Also
Syntax
function hide([effectName: string], [effectOptions: ArcEffectOptions | BounceEffectOptions | FadeEffectOptions | FlipEffectOptions | FloatEffectOptions | FlyEffectOptions | FoldEffectOptions | GlideEffectOptions | PuffEffectOptions | RollEffectOptions | SlideEffectOptions | SpinEffectOptions | TurnEffectOptions | ZoomEffectOptions]): Promise<void>
The name of the effect to play when hiding the item.
hidden
property has been set to true
.MIXED IN FROM
Examples
Hide an element with no effect
$w("#myElement").hide();
Hide an element with the "fade" effect
$w("#myElement").hide("fade");
Hide an element with the "fade" effect and custom options
let fadeOptions = {
"duration": 2000,
"delay": 1000
};
$w("#myElement").hide("fade", fadeOptions);
Hide an element with an effect and log a message when the effect is done
$w("#myElement").hide("fade")
.then( ( ) => {
console.log("Done with fade");
} );
Toggle an element's hidden state
if( $w("#myElement").hidden ) {
$w("#myElement").show();
}
else {
$w("#myElement").hide();
}
onBlur( )
Description
An element loses focus (blurs) through user actions, such as clicking and tabbing, or programmatically, using the blur( ) function.
Note
onBlur()
has no effect when applied to RadioButtonGroup elements.
Deprecation note: The $w parameter of event handlers is being deprecated. To get
a scoped selector for working with elements in repeater items, use the $w.at() function
and pass it the context property of the event parameter: $item = $w.at(event.context)
. To learn more, see
here.
See Also
Syntax
function onBlur(handler: EventHandler): Element
callback EventHandler(event: Event, $w: $w): void
The name of the function or the function expression to run when the element losed focus.
MIXED IN FROM
Examples
Get the ID of the element that has lost focus
$w("#myElement").onBlur( (event) => {
let targetId = event.target.id; // "myElement"
});
onError( )
Description
The onError()
function allows you to perform actions when the reCAPTCHA element on the client side
loses connection with the CAPTCHA provider.
If an error occurs, the reCAPTCHA element automatically resets. You can ask the site visitor to retry the CAPTCHA challenge later.
Syntax
function onError(handler: ErrorHandler): void
callback ErrorHandler(): void
The name of the function or the function expression to run when an error occurs.
Examples
Register a callback to run when an error occurs
In this example, the onError() event handler runs, indicating a connection problem. We flash a temporary message instructing site visitors to try complete the challenge later.
$w("#myCaptcha").onError(() => {
$w("#messageText").text = "The reCAPTCHA element lost connection with the CAPTCHA provider. Try again later.";
$w("#messageText").show()
.then(() => {
$w("#messageText").hide("fade", {"delay": 10000});
} );
} );
onFocus( )
Description
An element receives focus through user actions, such as clicking and tabbing, or programmatically, using the focus( ) function.
Note
onFocus()
has no effect when applied to RadioButtonGroup elements.
Deprecation note: The $w parameter of event handlers is being deprecated. To get
a scoped selector for working with elements in repeater items, use the $w.at() function
and pass it the context property of the event parameter: $item = $w.at(event.context)
. To learn more, see
here.
See Also
Syntax
function onFocus(handler: EventHandler): Element
callback EventHandler(event: Event, $w: $w): void
The name of the function or the function expression to run when the element receives focus.
MIXED IN FROM
Examples
Get the ID of the element that has received focus
$w("#myElement").onFocus( (event) => {
let targetId = event.target.id; // "myElement"
});
onMouseIn( )
Adds an event handler that runs when the mouse pointer is moved onto the element.
Note
Deprecation note: The $w parameter of event handlers is being deprecated. To get
a scoped selector for working with elements in repeater items, use the $w.at() function
and pass it the context property of the event parameter: $item = $w.at(event.context)
. To learn more, see
here.
Syntax
function onMouseIn(handler: MouseEventHandler): Element
callback MouseEventHandler(event: MouseEvent, $w: $w): void
The name of the function or the function expression to run when the mouse pointer is moved onto the element.
MIXED IN FROM
Examples
Get the mouse event info when the mouse enters an element
$w("#myElement").onMouseIn( (event) => {
let clientX = event.clientX; // 362
let clientY = event.clientY; // 244
let offsetX = event.offsetX; // 10
let offsetY = event.offsetY; // 12
let pageX = event.pageX; // 362
let pageY = event.pageY; // 376
let screenX = event.screenX; // 3897
let screenY = event.screenY; // 362
} );
onMouseOut( )
Adds an event handler that runs when the mouse pointer is moved off of the element.
Note
Deprecation note: The $w parameter of event handlers is being deprecated. To get
a scoped selector for working with elements in repeater items, use the $w.at() function
and pass it the context property of the event parameter: $item = $w.at(event.context)
. To learn more, see
here.
Syntax
function onMouseOut(handler: MouseEventHandler): Element
callback MouseEventHandler(event: MouseEvent, $w: $w): void
The name of the function or the function expression to run when the mouse pointer is moved off of the element.
MIXED IN FROM
Examples
Get the mouse event info when the mouse exits an element
$w("#myElement").onMouseOut( (event) => {
let clientX = event.clientX; // 362
let clientY = event.clientY; // 244
let offsetX = event.offsetX; // 10
let offsetY = event.offsetY; // 12
let pageX = event.pageX; // 362
let pageY = event.pageY; // 376
let screenX = event.screenX; // 3897
let screenY = event.screenY; // 362
} );
onTimeout( )
Description
The onTimeout()
function allows you to perform actions when a CAPTCHA timeout occurs.
When a site visitor completes a CAPTCHA challenge, a token
is
generated. If 120 seconds pass without backend authorization,
the token expires and onTimeout()
is called.
When a timeout occurs, the reCAPTCHA element automatically resets and displays a message asking the site visitor to redo the challenge. If you enabled the clickable element for triggering a restricted operation when the CAPTCHA was verified, disable it.
Syntax
function onTimeout(handler: TimeoutHandler): void
callback TimeoutHandler(): void
The name of the function or the function expression to run when a CAPTCHA timeout occurs.
Examples
Register a callback to run when a timeout occurs
$w("#myCaptcha").onTimeout(() => {
$w("#submitDataButton").disable();
$w("#messageText").text = "The CAPTCHA has timed out. Please redo the CAPTCHA challenge.";
$w("#messageText").show();
} );
onVerified( )
Description
Once the CAPTCHA challenge has been successfully completed by the user, the onVerified
callback is triggered and a CAPTCHA token is generated.
If the clickable element for triggering the submit or another restricted operation was disabled, enable it.
Syntax
function onVerified(handler: VerifiedHandler): void
callback VerifiedHandler(): Promise<void>
The name of the function or the function expression to run when the CAPTCHA is verified.
Examples
Register a callback to run when the CAPTCHA is verified
$w("#myCaptcha").onVerified(() => {
$w("#signupButton").enable();
let myToken = $w("#myCaptcha").token;
} );
Full CAPTCHA lifecycle scenario
This example demonstrates how to use reCAPTCHA to protect a data insertion. We use a text input for the data, a reCAPTCHA element, and a submit button. The submit button is disabled until the CAPTCHA is verified and a token is generated. Clicking the submit button triggers backend authorization of the token. If authorization is successful, the data is inserted into the collection.
/************************************
* backend code - submitHandler.jsw *
************************************/
import wixCaptcha from 'wix-captcha-backend';
import wixData from 'wix-data';
// Authorize token and insert data
export function processSubmission(submitRequestData) {
return wixCaptcha.authorize(submitRequestData.token)
.then( () => {
return wixData.insert("MyCollection", submitRequestData.data)
.then( () => ({"type": "success"}))
.catch( (error) => ({"type": "insertion error", "message": "Error: collection insertion failed: " + error}));
})
.catch( (error) => ({"type": "authorization error", "message": "Error: reCAPTCHA authorization failed: " + error}));
}
/********************
* client-side code *
********************/
import {processSubmission} from 'backend/submitHandler';
$w.onReady(function () {
// When user clicks submit button
$w("#submitDataButton").onClick(() => {
let submitRequestData = {
token: $w("#myCaptcha").token,
data: $w("#myInput").value,
}
processSubmission(submitRequestData) // Call backend function
.then( (response) => {
// Display a different message depending on response from backend function
switch(response.type){
case "success":
$w("#messageText").text = "Data successfully submitted";
break;
case "authorization error":
$w("#messageText").text = "CAPTCHA authorization failed. Redo the CAPTCHA challenge.";
break;
case "insertion error":
$w("#messageText").text = "Database error. Redo the CAPTCHA challenge.";
break;
}
$w("#myCaptcha").reset();
$w("#submitDataButton").disable();
$w("#messageText").show();
});
});
// Error handler
$w("#myCaptcha").onError(() => {
$w("#messageText").text = "The reCAPTCHA element lost connection with the CAPTCHA provider. Try again later.";
$w("#messageText").show()
.then(() => {
$w("#messageText").hide("fade", {"delay": 10000});
} );
})
// Verification handler
$w("#myCaptcha").onVerified(() => {
$w("#submitDataButton").enable();
$w("#messageText").hide();
})
// Timeout handler
$w("#myCaptcha").onTimeout(() => {
$w("#submitDataButton").disable();
$w("#messageText").text = "The CAPTCHA has timed out. Please redo the CAPTCHA challenge.";
$w("#messageText").show();
});
});
onViewportEnter( )
Adds an event handler that runs when an element is displayed in the viewable part of the current window.
Description
An element enters the viewport when the page is scrolled to show any
part of the element. An element also enters the viewport if it was
hidden or collapsed
and is then shown or expanded in the viewable part of the current window. onViewportEnter()
is not fired for hidden or collapsed
elements even if they are scrolled into view.
Note
Deprecation note: The $w parameter of event handlers is being deprecated. To get
a scoped selector for working with elements in repeater items, use the $w.at() function
and pass it the context property of the event parameter: $item = $w.at(event.context)
. To learn more, see
here.
See Also
Syntax
function onViewportEnter(handler: EventHandler): Element
callback EventHandler(event: Event, $w: $w): void
The name of the function or the function expression to run when the element enters the viewport.
MIXED IN FROM
Examples
Get the ID of the element that has entered the viewport
$w("#myElement").onViewportEnter( (event) => {
let targetId = event.target.id; // "myElement"
});
onViewportLeave( )
Adds an event handler that runs when an element is no longer displayed in the viewable part of the current window.
Description
An element leaves the viewport when the page is scrolled so that the
element is completely out of view. An element also leaves the viewport
if it was shown or expanded and is then hidden
or collapsed from the viewable part
of the current window. onViewportLeave()
is not fired for hidden or collapsed
elements even if they are scrolled out of view.
Note
Deprecation note: The $w parameter of event handlers is being deprecated. To get
a scoped selector for working with elements in repeater items, use the $w.at() function
and pass it the context property of the event parameter: $item = $w.at(event.context)
. To learn more, see
here.
See Also
Syntax
function onViewportLeave(handler: EventHandler): Element
callback EventHandler(event: Event, $w: $w): void
The name of the function or the function expression to run when the element leaves the viewport.
MIXED IN FROM
Examples
Get the ID of the element that has left the viewport
$w("#myElement").onViewportLeave( (event) => {
let targetId = event.target.id; // "myElement"
});
reset( )
Description
reset()
the reCAPTCHA element in the following cases:
- CAPTCHA fails authorization
- The operation restricted by the reCAPTCHA element is successfully completed. This enables the reCAPTCHA element for the next operation.
Syntax
function reset(): Promise<void>
Examples
Reset the reCAPTCHA element
$w("#myCaptcha").reset();
Full CAPTCHA lifecycle scenario
This example demonstrates how to use reCAPTCHA to protect a data insertion. We use a text input for the data, a reCAPTCHA element, and a submit button. The submit button is disabled until the CAPTCHA is verified and a token is generated. Clicking the submit button triggers backend authorization of the token. If authorization is successful, the data is inserted into the collection.
/************************************
* backend code - submitHandler.jsw *
************************************/
import wixCaptcha from 'wix-captcha-backend';
import wixData from 'wix-data';
// Authorize token and insert data
export function processSubmission(submitRequestData) {
return wixCaptcha.authorize(submitRequestData.token)
.then( () => {
return wixData.insert("MyCollection", submitRequestData.data)
.then( () => ({"type": "success"}))
.catch( (error) => ({"type": "insertion error", "message": "Error: collection insertion failed: " + error}));
})
.catch( (error) => ({"type": "authorization error", "message": "Error: reCAPTCHA authorization failed: " + error}));
}
/********************
* client-side code *
********************/
import {processSubmission} from 'backend/submitHandler';
$w.onReady(function () {
// When user clicks submit button
$w("#submitDataButton").onClick(() => {
let submitRequestData = {
token: $w("#myCaptcha").token,
data: $w("#myInput").value,
}
processSubmission(submitRequestData) // Call backend function
.then( (response) => {
// Display a different message depending on response from backend function
switch(response.type){
case "success":
$w("#messageText").text = "Data successfully submitted";
break;
case "authorization error":
$w("#messageText").text = "CAPTCHA authorization failed. Redo the CAPTCHA challenge.";
break;
case "insertion error":
$w("#messageText").text = "Database error. Redo the CAPTCHA challenge.";
break;
}
$w("#myCaptcha").reset();
$w("#submitDataButton").disable();
$w("#messageText").show();
});
});
// Error handler
$w("#myCaptcha").onError(() => {
$w("#messageText").text = "The reCAPTCHA element lost connection with the CAPTCHA provider. Try again later.";
$w("#messageText").show()
.then(() => {
$w("#messageText").hide("fade", {"delay": 10000});
} );
})
// Verification handler
$w("#myCaptcha").onVerified(() => {
$w("#submitDataButton").enable();
$w("#messageText").hide();
})
// Timeout handler
$w("#myCaptcha").onTimeout(() => {
$w("#submitDataButton").disable();
$w("#messageText").text = "The CAPTCHA has timed out. Please redo the CAPTCHA challenge.";
$w("#messageText").show();
});
});
scrollTo( )
Description
The scrollTo()
function returns a Promise that is resolved when the
animated scroll is complete and the element is now in view.
To scroll to a specific location on the page, see the wix-window
scrollTo()
function.
Calling the scrollTo()
function on an element in a repeated item that
is selected from the global scope causes
an error.
Syntax
function scrollTo(): Promise<void>
MIXED IN FROM
Examples
Scroll the page to an element
$w("#myElement").scrollTo();
Scroll the page to an element and log message when done
$w("#myElement").scrollTo()
.then( ( ) => {
console.log("Done with scroll");
} );
show( )
Shows the element and sets its hidden
property
to false
, using an effect if specified.
Description
The show()
function shows the element and returns a Promise that is
resolved when the effect is complete and the element's hidden
property has been set to false
.
You can optionally apply an effect when showing the element by providing
an effectName
value. You can also customize the effect by providing the
optional effectOptions
object.
Effects:
See Also
Syntax
function show([effectName: string], [effectOptions: ArcEffectOptions | BounceEffectOptions | FadeEffectOptions | FlipEffectOptions | FloatEffectOptions | FlyEffectOptions | FoldEffectOptions | GlideEffectOptions | PuffEffectOptions | RollEffectOptions | SlideEffectOptions | SpinEffectOptions | TurnEffectOptions | ZoomEffectOptions]): Promise<void>
The name of the effect to play when showing the item.
hidden
property has been set to false
.MIXED IN FROM
Examples
Show an element with no effect
$w("#myElement").show();
Show an element with the "fade" effect
$w("#myElement").show("fade");
Show an element with the "fade" effect and custom options
let fadeOptions = {
"duration": 2000,
"delay": 1000
};
$w("#myElement").show("fade", fadeOptions);
Show an element with an effect and log a message when the effect is done
$w("#myElement").show("fade")
.then( ( ) => {
console.log("Done with fade");
} );
Toggle an element's hidden state
if( $w("#myElement").hidden ) {
$w("#myElement").show();
}
else {
$w("#myElement").hide();
}