-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Text-Input widget #616
Labels
Comments
This was referenced Nov 9, 2018
3 tasks
nicknisi
added a commit
that referenced
this issue
Feb 26, 2019
**Type:** feature The following has been addressed in the PR: * [x] There is a related issue * [x] All code matches the [style guide](https://github.com/dojo/meta/blob/master/STYLE.md) * [x] Unit or Functional tests are included in the PR <!-- Our bots should ensure: * [ ] All contributors have signed a CLA * [ ] The PR passes CI testing * [ ] Code coverage is maintained * [ ] The PR has been reviewed and approved --> **Description:** This adds validation support as partially described in #616. The user can provide a `validate` property to the widget, which if `true`, will validate against the `type` (`"email"`, for example) and use the browser's built-in validation. Alternatively, `validate` can be a function that accepts the widget's current value as an argument and must return `{ valid: boolean; message: string | undefined; }`. The user can also provide an `onValidate(valid: boolean, message?: string)` which will be called to pass the validation value back up to the parent, along with any potential message. With the current behavior, if `validate` is a function, it is the primary validation, but the other validation (email, for example) is also being checked. **Example:** ```typescript w(TextInput, { key: 't2', type: 'email', label: 'Email (required)', required: true, // validate: true, validate(value: string) { const valid = !!~value.indexOf('nicknisi'); return { valid, message: !valid ? 'Must include nicknisi' : '' }; }, onValidate(valid: boolean, message: string | undefined) { const color = valid ? 'green' : 'red'; console.log(`%c${message}`, `font-weight:bold;color:${color};`, { valid }); }, value: this._value2, onInput: (value: string) => { this._value2 = value; this.invalidate(); } }) ``` ![2019-02-18 21 58 28](https://user-images.githubusercontent.com/293805/52989302-61468c80-33c8-11e9-8d47-fa93b4304fa2.gif) ### Breaking changes This PR removes the `invalid` property. The way to mark an input as invalid is to use custom validation. This also slightly affects combobox and enhanced text input as their `invalid` properties will no longer be passed down to the underlying text-input widget.
This has been completed |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Overview
This issue is concerned with implementing a material themed text input component.
Native browser validation will be added to the widget controlled by a
validate
flag. A custom validator may also be used.Changes to structure
leading: DNode
andtrailing: DNode
. This will replaceEnhanced-Text-Input
.label
if specified will be renderedbefore
the widget and the option to renderafter
will be removed. Users wishing to use alabel
after an input can do so by manually rendering alabel
widget and linking it to the input viafor
andid
.New properties
onValue(value: string) => void
: callback upon value change, this will replaceonInput
callback.onKey(key: number, preventDefault: () => void)
: callback onkeyPress
leading: DNode
will render a leading section before the inputtrailing: DNode
will render a trailing section after the inputvalidate: boolean | (value: string) => { message: string; valid: boolean }
: flag to indicate if widget should validate or callback to perform custom validation.onValidate: (valid: boolean) => void
: callback upon validation to inform parent of valid state.Breaking changes
labelAfter
propertyonChange
callbackkeyDown
/keyPress
onBlur
/onFocus
will no longer be passed thevalue
Future work / properties
outlined: boolean
renders the text input with an outline rather than with a line beneath it (this is a material property)fullWidth: boolean
renders the text input full width and treats the label differently (this is a material property)helperText: string
used to provide helper text beneath the text-input (this is a material property)Tasks
The text was updated successfully, but these errors were encountered: