mirror of
https://github.com/gristlabs/grist-core.git
synced 2024-10-27 20:44:07 +00:00
698c9d4e40
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
28 lines
790 B
JavaScript
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;
|