Skip to content
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

Closed
3 tasks
tomdye opened this issue Nov 9, 2018 · 1 comment
Closed
3 tasks

Text-Input widget #616

tomdye opened this issue Nov 9, 2018 · 1 comment

Comments

@tomdye
Copy link
Member

tomdye commented Nov 9, 2018

screenshot 2018-11-09 13 09 46

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

  • Widget will be expanded to take arguments of leading: DNode and trailing: DNode. This will replace Enhanced-Text-Input.
  • label if specified will be rendered before the widget and the option to render after will be removed. Users wishing to use a label after an input can do so by manually rendering a label widget and linking it to the input via for and id.

New properties

  • onValue(value: string) => void: callback upon value change, this will replace onInput callback.
  • onKey(key: number, preventDefault: () => void): callback on keyPress
  • leading: DNode will render a leading section before the input
  • trailing: DNode will render a trailing section after the input
  • validate: 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

  • will no longer offer labelAfter property
  • will no longer call an onChange callback
  • will no longer call keyDown / keyPress
  • specific touch events have been removed
  • onBlur / onFocus will no longer be passed the value

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

  • Restructure and update props
  • Implement theme and update dojo theme
  • Add validation
@tomdye tomdye added the material label Nov 9, 2018
@tomdye tomdye self-assigned this Nov 9, 2018
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.
@tomdye
Copy link
Member Author

tomdye commented Mar 22, 2021

This has been completed

@tomdye tomdye closed this as completed Mar 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant