* Some WIP inputType

This commit is contained in:
Bryan Ashby 2015-04-07 23:15:34 -06:00
parent 9bc1e2f3d1
commit 6d84018ef5
3 changed files with 38 additions and 6 deletions

View file

@ -10,11 +10,14 @@ var assert = require('assert');
exports.EditTextView = EditTextView;
function EditTextView(client, options) {
options.acceptsFocus = miscUtil.valueWithDefault(options.acceptsFocus, true);
options.acceptsInput = miscUtil.valueWithDefault(options.acceptsInput, true);
options.acceptsFocus = miscUtil.valueWithDefault(options.acceptsFocus, true);
options.acceptsInput = miscUtil.valueWithDefault(options.acceptsInput, true);
options.inputType = miscUtil.valueWithDefault(options.inputType, 'normal');
TextView.call(this, client, options);
assert(this.inputType in EditTextView.InputTypes);
this.clientBackspace = function() {
this.client.term.write(
'\b' + this.getANSIColor(this.getColor()) + this.fillChar + '\b' + this.getANSIColor(this.getFocusColor()));
@ -23,6 +26,27 @@ function EditTextView(client, options) {
util.inherits(EditTextView, TextView);
EditTextView.InputTypes = {
normal : 1,
email : 2,
numeric : 3,
alpha : 4,
alphaNumeric : 5,
phone : 6,
};
Object.freeze(EditTextView.InputTypes);
EditTextView.prototype.isKeyValidForInputType = function(key) {
// :TODO: add in the actual validations:
switch(this.inputType) {
case 'normal' : return true;
case 'email' : return true; // :TODO: validate based on char + position
case 'numeric' : return !isNaN(key);
}
return true;
};
EditTextView.prototype.onKeyPress = function(key, isSpecial) {
if(isSpecial) {
return;
@ -30,6 +54,10 @@ EditTextView.prototype.onKeyPress = function(key, isSpecial) {
assert(1 === key.length);
if(!this.isKeyValidForInputType(key)) {
return;
}
// :TODO: how to handle justify left/center?
if(this.text.length < this.options.maxLength) {