add button.value. add simple form example.

This commit is contained in:
Christopher Jeffrey 2013-08-13 10:54:17 -05:00
parent 185a05d759
commit 6f9ae457e4
2 changed files with 90 additions and 1 deletions

87
example/simple-form.js Normal file
View File

@ -0,0 +1,87 @@
var blessed = require('blessed')
, screen = blessed.screen();
var form = blessed.form({
parent: screen,
keys: true,
left: 0,
top: 0,
width: 30,
height: 4,
bg: 'green',
content: 'Submit or cancel?'
});
var submit = blessed.button({
parent: form,
mouse: true,
keys: true,
shrink: true,
padding: {
left: 1,
right: 1
},
left: 10,
top: 2,
shrink: true,
name: 'submit',
content: 'submit',
style: {
bg: 'blue',
focus: {
bg: 'red'
},
hover: {
bg: 'red'
}
}
});
var cancel = blessed.button({
parent: form,
mouse: true,
keys: true,
shrink: true,
padding: {
left: 1,
right: 1
},
left: 20,
top: 2,
shrink: true,
name: 'cancel',
content: 'cancel',
style: {
bg: 'blue',
focus: {
bg: 'red'
},
hover: {
bg: 'red'
}
}
});
submit.on('press', function() {
form.submit();
});
cancel.on('press', function() {
form.reset();
});
form.on('submit', function(data) {
form.setContent('Submitted.');
screen.render();
});
form.on('reset', function(data) {
form.setContent('Canceled.');
screen.render();
});
screen.key('q', function() {
process.exit(0);
});
screen.render();

View File

@ -4312,6 +4312,7 @@ Form.prototype.reset = function() {
el.clearInput();
return;
case 'button':
delete el.value;
break;
case 'progress-bar':
el.setProgress(0);
@ -4762,8 +4763,9 @@ Button.prototype.__proto__ = Input.prototype;
Button.prototype.type = 'button';
Button.prototype.press = function() {
var self = this;
this.value = true;
this.emit('press');
delete this.value;
};
/**