gristlabs_grist-core/app/client/widgets/ChoiceEditor.js
Jarosław Sadziński 698c9d4e40 (core) Readonly editors
Summary:
Grist should not prevent read-only viewers from opening cell editors since they usually provide much more information than is visible in a cell.

Every editor was enhanced with a read-only mode that provides the same information available for an editor but doesn't allow to change the underlying data.

Test Plan: Browser tests

Reviewers: dsagal

Reviewed By: dsagal

Differential Revision: https://phab.getgrist.com/D2842
2021-06-17 19:12:16 +02:00

28 lines
790 B
JavaScript

var _ = require('underscore');
var dispose = require('../lib/dispose');
var TextEditor = require('./TextEditor');
const {autocomplete} = require('app/client/ui2018/menus');
/**
* ChoiceEditor - TextEditor with a dropdown for possible choices.
*/
function ChoiceEditor(options) {
TextEditor.call(this, options);
this.choices = options.field.widgetOptionsJson.peek().choices || [];
// Add autocomplete if there are any choices to select from
if (this.choices.length > 0 && !options.readonly) {
autocomplete(this.textInput, this.choices, {
allowNothingSelected: true,
onClick: () => this.options.commands.fieldEditSave(),
});
}
}
dispose.makeDisposable(ChoiceEditor);
_.extend(ChoiceEditor.prototype, TextEditor.prototype);
module.exports = ChoiceEditor;