* Some WIP inputType
This commit is contained in:
parent
9bc1e2f3d1
commit
6d84018ef5
|
@ -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) {
|
||||
|
|
|
@ -13,21 +13,24 @@ exports.TextView = TextView;
|
|||
function TextView(client, options) {
|
||||
View.call(this, client, options);
|
||||
|
||||
var self = this;
|
||||
|
||||
if(this.options.maxLength) {
|
||||
this.maxLength = this.options.maxLength;
|
||||
}
|
||||
|
||||
this.multiLine = this.options.multiLine || false;
|
||||
this.fillChar = miscUtil.valueWithDefault(this.options.fillChar, ' ').substr(0, 1);
|
||||
|
||||
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
|
||||
|
||||
if(!this.multiLine) {
|
||||
this.dimens.height = 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
this.drawText = function(s) {
|
||||
|
|
|
@ -39,7 +39,7 @@ function View(client, options) {
|
|||
|
||||
this.textStyle = this.options.textStyle || 'normal';
|
||||
this.focusTextStyle = this.options.focusTextStyle || this.textStyle;
|
||||
|
||||
|
||||
if(this.options.id) {
|
||||
this.setId(this.options.id);
|
||||
}
|
||||
|
@ -48,7 +48,8 @@ function View(client, options) {
|
|||
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
|
||||
if(this.options.dimens && this.options.dimens.height) {
|
||||
|
|
Loading…
Reference in New Issue