diff --git a/example/simple-form.js b/example/simple-form.js new file mode 100644 index 0000000..cedf37e --- /dev/null +++ b/example/simple-form.js @@ -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(); diff --git a/lib/widget.js b/lib/widget.js index 00a2040..7fe6e70 100644 --- a/lib/widget.js +++ b/lib/widget.js @@ -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; }; /**