* Some WIP inputType
This commit is contained in:
parent
9bc1e2f3d1
commit
6d84018ef5
|
@ -10,11 +10,14 @@ var assert = require('assert');
|
||||||
exports.EditTextView = EditTextView;
|
exports.EditTextView = EditTextView;
|
||||||
|
|
||||||
function EditTextView(client, options) {
|
function EditTextView(client, options) {
|
||||||
options.acceptsFocus = miscUtil.valueWithDefault(options.acceptsFocus, true);
|
options.acceptsFocus = miscUtil.valueWithDefault(options.acceptsFocus, true);
|
||||||
options.acceptsInput = miscUtil.valueWithDefault(options.acceptsInput, true);
|
options.acceptsInput = miscUtil.valueWithDefault(options.acceptsInput, true);
|
||||||
|
options.inputType = miscUtil.valueWithDefault(options.inputType, 'normal');
|
||||||
|
|
||||||
TextView.call(this, client, options);
|
TextView.call(this, client, options);
|
||||||
|
|
||||||
|
assert(this.inputType in EditTextView.InputTypes);
|
||||||
|
|
||||||
this.clientBackspace = function() {
|
this.clientBackspace = function() {
|
||||||
this.client.term.write(
|
this.client.term.write(
|
||||||
'\b' + this.getANSIColor(this.getColor()) + this.fillChar + '\b' + this.getANSIColor(this.getFocusColor()));
|
'\b' + this.getANSIColor(this.getColor()) + this.fillChar + '\b' + this.getANSIColor(this.getFocusColor()));
|
||||||
|
@ -23,6 +26,27 @@ function EditTextView(client, options) {
|
||||||
|
|
||||||
util.inherits(EditTextView, TextView);
|
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) {
|
EditTextView.prototype.onKeyPress = function(key, isSpecial) {
|
||||||
if(isSpecial) {
|
if(isSpecial) {
|
||||||
return;
|
return;
|
||||||
|
@ -30,6 +54,10 @@ EditTextView.prototype.onKeyPress = function(key, isSpecial) {
|
||||||
|
|
||||||
assert(1 === key.length);
|
assert(1 === key.length);
|
||||||
|
|
||||||
|
if(!this.isKeyValidForInputType(key)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// :TODO: how to handle justify left/center?
|
// :TODO: how to handle justify left/center?
|
||||||
|
|
||||||
if(this.text.length < this.options.maxLength) {
|
if(this.text.length < this.options.maxLength) {
|
||||||
|
|
|
@ -13,14 +13,18 @@ exports.TextView = TextView;
|
||||||
function TextView(client, options) {
|
function TextView(client, options) {
|
||||||
View.call(this, client, options);
|
View.call(this, client, options);
|
||||||
|
|
||||||
|
var self = this;
|
||||||
|
|
||||||
if(this.options.maxLength) {
|
if(this.options.maxLength) {
|
||||||
this.maxLength = this.options.maxLength;
|
this.maxLength = this.options.maxLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.multiLine = this.options.multiLine || false;
|
this.multiLine = this.options.multiLine || false;
|
||||||
this.fillChar = miscUtil.valueWithDefault(this.options.fillChar, ' ').substr(0, 1);
|
this.fillChar = miscUtil.valueWithDefault(this.options.fillChar, ' ').substr(0, 1);
|
||||||
|
|
||||||
this.justify = this.options.justify || 'right';
|
this.justify = this.options.justify || 'right';
|
||||||
|
this.inputType = this.options.inputType || 'normal';
|
||||||
|
|
||||||
|
this.isPasswordTextStyle = 'P' === this.textStyle || 'password' === this.textStyle;
|
||||||
|
|
||||||
assert(!this.multiLine); // :TODO: not yet supported
|
assert(!this.multiLine); // :TODO: not yet supported
|
||||||
|
|
||||||
|
@ -29,7 +33,6 @@ function TextView(client, options) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
this.drawText = function(s) {
|
this.drawText = function(s) {
|
||||||
var ansiColor = this.getANSIColor(this.hasFocus ? this.getFocusColor() : this.getColor());
|
var ansiColor = this.getANSIColor(this.hasFocus ? this.getFocusColor() : this.getColor());
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,8 @@ function View(client, options) {
|
||||||
this.setPosition(this.options.position);
|
this.setPosition(this.options.position);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.isPasswordTextStyle = 'P' === this.textStyle || 'password' === this.textStyle;
|
|
||||||
|
// this.isPasswordTextStyle = 'P' === this.textStyle || 'password' === this.textStyle;
|
||||||
|
|
||||||
// :TODO: Don't allow width/height > client.term
|
// :TODO: Don't allow width/height > client.term
|
||||||
if(this.options.dimens && this.options.dimens.height) {
|
if(this.options.dimens && this.options.dimens.height) {
|
||||||
|
|
Loading…
Reference in New Issue