diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2021-02-24 22:23:40 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-24 22:23:40 -0500 |
commit | 6bda81b4220cf6057f24e5b08aa9a62e4e535bc2 (patch) | |
tree | 62a73f8270e0e044f18f8a1d395fec7e86573154 /ext/js/data | |
parent | ae92e0b3781e27d54cbac2570ba2a1b8a6b11999 (diff) |
Improve note addability (#1440)
* Add valid field
* Add isNoteDataValid function
* Update _areDefinitionsAddableForcedValue to return proper valid values
* Refactor isAnkiConnected check
* Force canAdd to false if not valid
Diffstat (limited to 'ext/js/data')
-rw-r--r-- | ext/js/data/anki-util.js | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/ext/js/data/anki-util.js b/ext/js/data/anki-util.js index fc081ddc..c815ccc7 100644 --- a/ext/js/data/anki-util.js +++ b/ext/js/data/anki-util.js @@ -81,6 +81,21 @@ class AnkiUtil { static cloneFieldMarkerPattern(global) { return new RegExp(this._markerPattern.source, global ? 'g' : ''); } + + /** + * Checks whether or not a note object is valid. + * @param note A note object to check. + * @return `true` if the note is valid, `false` otherwise. + */ + static isNoteDataValid(note) { + if (!isObject(note)) { return false; } + const {fields, deckName, modelName} = note; + return ( + typeof deckName === 'string' && + typeof modelName === 'string' && + Object.entries(fields).length > 0 + ); + } } // eslint-disable-next-line no-underscore-dangle |