Skip to content

Instantly share code, notes, and snippets.

@tbuschto
Created November 2, 2018 17:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tbuschto/05a73bdb94efcc38586643999416d9c2 to your computer and use it in GitHub Desktop.
Save tbuschto/05a73bdb94efcc38586643999416d9c2 to your computer and use it in GitHub Desktop.
LabeledInput with data binding
import { Composite, ui, AlertDialog } from 'tabris';
import { bind, component, property, ComponentJSX } from 'tabris-decorators';
// ------------ Component ------------
@component
export default class LabeledInput extends Composite {
@bind('#input.text') public text: string;
@property public labelText: string;
private jsxProperties: ComponentJSX<this>;
constructor(properties: Partial<LabeledInput>) {
super(properties);
this.append(
<widgetCollection>
<textView id='label'
height={32} centerY={0}
bind-text='labelText'
font='20px'/>
<textInput id='input'
left='prev() 12' width={250}
font='20px'/>
</widgetCollection>
);
}
}
// ---------- Example App ------------
ui.contentView.append(
<widgetCollection>
<LabeledInput id='firstname' labelText='First name:'/>
<LabeledInput id='lastname' labelText='Last name:'/>
<button onSelect={showName} text='OK'/>
</widgetCollection>
).children().set({left: 12, top: 'prev() 12'});
function showName() {
const firstName = ui.find('#firstname').first(LabeledInput).text;
const lastName = ui.find('#lastname').first(LabeledInput).text;
new AlertDialog({message: `Hello ${firstName} ${lastName}!`}).open();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment