Skip to content
This repository was archived by the owner on Dec 19, 2024. It is now read-only.

Commit 4b6c1c5

Browse files
authored
Add TypeScript declarations to iron-validatable-behavior. (#39)
* Generate minimal package.json from bower.json * Update and/or configure type declarations.
1 parent 9588c7c commit 4b6c1c5

File tree

5 files changed

+1074
-0
lines changed

5 files changed

+1074
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
bower_components*
22
bower-*.json
3+
node_modules

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ sudo: required
33
before_script:
44
- npm install -g polymer-cli
55
- polymer install --variants
6+
- >-
7+
npm run update-types && git diff --exit-code || (echo -e
8+
'\n\033[31mERROR:\033[0m Typings are stale. Please run "npm run
9+
update-types".' && false)
610
env:
711
global:
812
- secure: >-

iron-validatable-behavior.d.ts

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/**
2+
* DO NOT EDIT
3+
*
4+
* This file was automatically generated by
5+
* https://github.com/Polymer/gen-typescript-declarations
6+
*
7+
* To modify these typings, edit the source file(s):
8+
* iron-validatable-behavior.html
9+
*/
10+
11+
/// <reference path="../polymer/types/polymer.d.ts" />
12+
/// <reference path="../iron-meta/iron-meta.d.ts" />
13+
14+
declare namespace Polymer {
15+
16+
/**
17+
* `Use Polymer.IronValidatableBehavior` to implement an element that validates user input.
18+
* Use the related `Polymer.IronValidatorBehavior` to add custom validation logic to an iron-input.
19+
*
20+
* By default, an `<iron-form>` element validates its fields when the user presses the submit button.
21+
* To validate a form imperatively, call the form's `validate()` method, which in turn will
22+
* call `validate()` on all its children. By using `Polymer.IronValidatableBehavior`, your
23+
* custom element will get a public `validate()`, which
24+
* will return the validity of the element, and a corresponding `invalid` attribute,
25+
* which can be used for styling.
26+
*
27+
* To implement the custom validation logic of your element, you must override
28+
* the protected `_getValidity()` method of this behaviour, rather than `validate()`.
29+
* See [this](https://github.com/PolymerElements/iron-form/blob/master/demo/simple-element.html)
30+
* for an example.
31+
*
32+
* ### Accessibility
33+
*
34+
* Changing the `invalid` property, either manually or by calling `validate()` will update the
35+
* `aria-invalid` attribute.
36+
*/
37+
interface IronValidatableBehavior {
38+
39+
/**
40+
* Name of the validator to use.
41+
*/
42+
validator: string|null|undefined;
43+
44+
/**
45+
* True if the last call to `validate` is invalid.
46+
*/
47+
invalid: boolean|null|undefined;
48+
49+
/**
50+
* Recompute this every time it's needed, because we don't know if the
51+
* underlying IronValidatableBehaviorMeta has changed.
52+
*/
53+
readonly _validator: any;
54+
registered(): void;
55+
_invalidChanged(): void;
56+
57+
/**
58+
* @returns True if the validator `validator` exists.
59+
*/
60+
hasValidator(): boolean;
61+
62+
/**
63+
* Returns true if the `value` is valid, and updates `invalid`. If you want
64+
* your element to have custom validation logic, do not override this method;
65+
* override `_getValidity(value)` instead.
66+
*
67+
* @param value Deprecated: The value to be validated. By default,
68+
* it is passed to the validator's `validate()` function, if a validator is set.
69+
* If this argument is not specified, then the element's `value` property
70+
* is used, if it exists.
71+
* @returns True if `value` is valid.
72+
*/
73+
validate(value: object|null): boolean;
74+
_getValidity(value: any): any;
75+
}
76+
77+
const IronValidatableBehavior: object;
78+
}

0 commit comments

Comments
 (0)