Constructor
new TextInputComponent()
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
options.text |
string |
<optional> |
'' | initial text |
options.dataField |
string |
<optional> |
'' | a field on the dataObject on which to bind |
options.placeholder |
string |
<optional> |
'' | text to show when the input is empty |
options.submitOnEnter |
bool |
<optional> |
true | trigger a submit event on `enter` keyUp event |
Examples
Set `TextInputComponent.text` to user's input (no DataModel)
const component = new TextInputComponent(undefined, {
text: 'Starting text',
placeholder: 'Enter some text here' // Shown when no text had been entered
})
// Listen for text changes
component.listenTo(TextInputComponent.TextChangeEvent, (eventName, textValue) => {
console.log('Text was input', textValue)
})
Bind text input to a DataModel field
const component = new TextInputComponent(myDataModel, {
dataField: 'biography',
placeholder: 'Tell us who you are', // Shown when no text had been entered
submitOnEnter: true
})
// Listen for text submission, usually by pressing the 'Enter' key
component.listenTo(TextInputComponent.TextSubmitEvent, (eventName, newValue) => {
console.log('New text was submitted', newValue)
})