Improve word forms

- Fix not clearing all fields
- Show advanced field if edited word has advanced data
This commit is contained in:
Robbie Antenesse 2020-07-31 11:39:54 -06:00
parent 6d7cdf68a9
commit fb42b0ef2b
2 changed files with 6 additions and 2 deletions

View File

@ -155,6 +155,8 @@ export function renderEditForm(wordId = false) {
wordId = typeof wordId.target === 'undefined' ? wordId : parseInt(this.id.replace('edit_', '')); wordId = typeof wordId.target === 'undefined' ? wordId : parseInt(this.id.replace('edit_', ''));
const word = window.currentDictionary.words.find(w => w.wordId === wordId); const word = window.currentDictionary.words.find(w => w.wordId === wordId);
if (word) { if (word) {
const wordHasAdvancedFields = (word.hasOwnProperty('etymology') && word.etymology)
|| (word.hasOwnProperty('related') && word.related) || (word.hasOwnProperty('principalParts') && word.principalParts);
const ipaPronunciationField = `<input id="wordPronunciation_${wordId}" class="ipa-field" maxlength="200" value="${word.pronunciation}"><br> const ipaPronunciationField = `<input id="wordPronunciation_${wordId}" class="ipa-field" maxlength="200" value="${word.pronunciation}"><br>
<a class="label-help-button ipa-field-help-button">Field Help</a>`; <a class="label-help-button ipa-field-help-button">Field Help</a>`;
const plainPronunciationField = `<input id="wordPronunciation_${wordId}" maxlength="200" value="${word.pronunciation}">`; const plainPronunciationField = `<input id="wordPronunciation_${wordId}" maxlength="200" value="${word.pronunciation}">`;
@ -177,9 +179,9 @@ export function renderEditForm(wordId = false) {
<textarea id="wordDetails_${wordId}" placeholder="Markdown formatting allowed">${word.details}</textarea> <textarea id="wordDetails_${wordId}" placeholder="Markdown formatting allowed">${word.details}</textarea>
</label> </label>
<label> <label>
<a id="expandAdvancedForm_${wordId}" class="small button expand-advanced-form">${window.settings.showAdvanced ? 'Hide' : 'Show'} Advanced Fields</a> <a id="expandAdvancedForm_${wordId}" class="small button expand-advanced-form">${wordHasAdvancedFields || window.settings.showAdvanced ? 'Hide' : 'Show'} Advanced Fields</a>
</label> </label>
<div id="advancedForm_${wordId}" class="advanced-word-form" style="display:${window.settings.showAdvanced ? 'block' : 'none'};"> <div id="advancedForm_${wordId}" class="advanced-word-form" style="display:${wordHasAdvancedFields || window.settings.showAdvanced ? 'block' : 'none'};">
<label>Etymology / Root Words<br> <label>Etymology / Root Words<br>
<input id="wordEtymology_${wordId}" maxlength="2500" placeholder="comma,separated,root,words" value="${word.hasOwnProperty('etymology') ? word.etymology : ''}"> <input id="wordEtymology_${wordId}" maxlength="2500" placeholder="comma,separated,root,words" value="${word.hasOwnProperty('etymology') ? word.etymology : ''}">
</label> </label>

View File

@ -228,6 +228,8 @@ export function clearWordForm() {
document.getElementById('wordDefinition').value = ''; document.getElementById('wordDefinition').value = '';
document.getElementById('wordDetails').value = ''; document.getElementById('wordDetails').value = '';
document.getElementById('wordEtymology').value = ''; document.getElementById('wordEtymology').value = '';
document.getElementById('wordRelated').value = '';
document.getElementById('wordPrincipalParts').value = '';
document.getElementById('wordName').focus(); document.getElementById('wordName').focus();
} }