diff --git a/src/addon/mod/data/fields/checkbox/component/checkbox.ts b/src/addon/mod/data/fields/checkbox/component/checkbox.ts index 98cbe5cc7..2db02302a 100644 --- a/src/addon/mod/data/fields/checkbox/component/checkbox.ts +++ b/src/addon/mod/data/fields/checkbox/component/checkbox.ts @@ -40,7 +40,7 @@ export class AddonModDataFieldCheckboxComponent extends AddonModDataFieldPluginC return; } - this.options = this.field.param1.split('\n').map((option) => { + this.options = this.field.param1.split(/\r?\n/).map((option) => { return { key: option, value: option }; }); @@ -67,7 +67,7 @@ export class AddonModDataFieldCheckboxComponent extends AddonModDataFieldPluginC * @param {any} value New value to be set. */ protected updateValue(value: any): void { - this.value = value; + this.value = value || {}; this.value.content = value && value.content && value.content.split('##').join('
'); } } diff --git a/src/addon/mod/data/fields/checkbox/providers/handler.ts b/src/addon/mod/data/fields/checkbox/providers/handler.ts index 48c50d8d7..3c3009394 100644 --- a/src/addon/mod/data/fields/checkbox/providers/handler.ts +++ b/src/addon/mod/data/fields/checkbox/providers/handler.ts @@ -80,14 +80,10 @@ export class AddonModDataFieldCheckboxHandler implements AddonModDataFieldHandle getFieldEditData(field: any, inputData: any, originalFieldData: any): any { const fieldName = 'f_' + field.id; - if (inputData[fieldName] && inputData[fieldName].length > 0) { - return [{ - fieldid: field.id, - value: inputData[fieldName] - }]; - } - - return false; + return [{ + fieldid: field.id, + value: inputData[fieldName] || [] + }]; } /** diff --git a/src/addon/mod/data/fields/file/providers/handler.ts b/src/addon/mod/data/fields/file/providers/handler.ts index 38a58e7de..d6e10b4b1 100644 --- a/src/addon/mod/data/fields/file/providers/handler.ts +++ b/src/addon/mod/data/fields/file/providers/handler.ts @@ -72,15 +72,11 @@ export class AddonModDataFieldFileHandler implements AddonModDataFieldHandler { getFieldEditData(field: any, inputData: any, originalFieldData: any): any { const files = this.getFieldEditFiles(field); - if (files.length) { - return [{ - fieldid: field.id, - subfield: 'file', - files: files - }]; - } - - return false; + return [{ + fieldid: field.id, + subfield: 'file', + files: files + }]; } /** diff --git a/src/addon/mod/data/fields/latlong/providers/handler.ts b/src/addon/mod/data/fields/latlong/providers/handler.ts index fb549c7c4..606db2878 100644 --- a/src/addon/mod/data/fields/latlong/providers/handler.ts +++ b/src/addon/mod/data/fields/latlong/providers/handler.ts @@ -66,26 +66,20 @@ export class AddonModDataFieldLatlongHandler implements AddonModDataFieldHandler * @return {any} With name and value of the data to be sent. */ getFieldEditData(field: any, inputData: any, originalFieldData: any): any { - const fieldName = 'f_' + field.id, - values = []; + const fieldName = 'f_' + field.id; - if (inputData[fieldName + '_0']) { - values.push({ + return [ + { fieldid: field.id, subfield: '0', - value: inputData[fieldName + '_0'] - }); - } - - if (inputData[fieldName + '_1']) { - values.push({ + value: inputData[fieldName + '_0'] || '' + }, + { fieldid: field.id, subfield: '1', - value: inputData[fieldName + '_1'] - }); - } - - return values; + value: inputData[fieldName + '_1'] || '' + } + ]; } /** diff --git a/src/addon/mod/data/fields/multimenu/component/multimenu.ts b/src/addon/mod/data/fields/multimenu/component/multimenu.ts index c642895f9..b31800229 100644 --- a/src/addon/mod/data/fields/multimenu/component/multimenu.ts +++ b/src/addon/mod/data/fields/multimenu/component/multimenu.ts @@ -40,7 +40,7 @@ export class AddonModDataFieldMultimenuComponent extends AddonModDataFieldPlugin return; } - this.options = this.field.param1.split('\n').map((option) => { + this.options = this.field.param1.split(/\r?\n/).map((option) => { return { key: option, value: option }; }); @@ -67,7 +67,7 @@ export class AddonModDataFieldMultimenuComponent extends AddonModDataFieldPlugin * @param {any} value New value to be set. */ protected updateValue(value: any): void { - this.value = value; + this.value = value || {}; this.value.content = value && value.content && value.content.split('##').join('
'); } } diff --git a/src/addon/mod/data/fields/multimenu/providers/handler.ts b/src/addon/mod/data/fields/multimenu/providers/handler.ts index 716da06bf..7c98f1b8c 100644 --- a/src/addon/mod/data/fields/multimenu/providers/handler.ts +++ b/src/addon/mod/data/fields/multimenu/providers/handler.ts @@ -80,14 +80,10 @@ export class AddonModDataFieldMultimenuHandler implements AddonModDataFieldHandl getFieldEditData(field: any, inputData: any, originalFieldData: any): any { const fieldName = 'f_' + field.id; - if (inputData[fieldName] && inputData[fieldName].length > 0) { - return [{ - fieldid: field.id, - value: inputData[fieldName] - }]; - } - - return false; + return [{ + fieldid: field.id, + value: inputData[fieldName] || [] + }]; } /** diff --git a/src/addon/mod/data/fields/number/providers/handler.ts b/src/addon/mod/data/fields/number/providers/handler.ts index fbf3fe68a..62308e6b5 100644 --- a/src/addon/mod/data/fields/number/providers/handler.ts +++ b/src/addon/mod/data/fields/number/providers/handler.ts @@ -49,12 +49,9 @@ export class AddonModDataFieldNumberHandler extends AddonModDataFieldTextHandler * @return {Promise | boolean} If the field has changes. */ hasFieldDataChanged(field: any, inputData: any, originalFieldData: any): Promise | boolean { - const fieldName = 'f_' + field.id, - input = typeof inputData[fieldName] != 'undefined' && inputData[fieldName] !== null ? - parseFloat(inputData[fieldName]) : ''; - - originalFieldData = (originalFieldData && typeof originalFieldData.content != 'undefined' && originalFieldData !== null) ? - parseFloat(originalFieldData.content) : ''; + const fieldName = 'f_' + field.id; + const input = inputData[fieldName] || ''; + originalFieldData = originalFieldData && originalFieldData.content || ''; return input != originalFieldData; } diff --git a/src/addon/mod/data/fields/picture/component/picture.ts b/src/addon/mod/data/fields/picture/component/picture.ts index dddf848d3..0c5836efa 100644 --- a/src/addon/mod/data/fields/picture/component/picture.ts +++ b/src/addon/mod/data/fields/picture/component/picture.ts @@ -124,13 +124,12 @@ export class AddonModDataFieldPictureComponent extends AddonModDataFieldPluginCo this.entryId = (value && value.recordid) || null; this.title = (value && value.content1) || ''; this.imageUrl = null; - if (this.image) { - if (this.image.offline) { - this.imageUrl = (this.image && this.image.toURL()) || null; - } else { - this.imageUrl = (this.image && this.image.fileurl) || null; + setTimeout(() => { + if (this.image) { + this.imageUrl = this.image.offline ? this.image.toURL() : this.image.fileurl; } - } + }, 1); + this.width = this.domUtils.formatPixelsSize(this.field.param1); this.height = this.domUtils.formatPixelsSize(this.field.param2); } diff --git a/src/addon/mod/data/fields/picture/providers/handler.ts b/src/addon/mod/data/fields/picture/providers/handler.ts index a5eab43b0..89abf7009 100644 --- a/src/addon/mod/data/fields/picture/providers/handler.ts +++ b/src/addon/mod/data/fields/picture/providers/handler.ts @@ -70,27 +70,21 @@ export class AddonModDataFieldPictureHandler implements AddonModDataFieldHandler * @return {any} With name and value of the data to be sent. */ getFieldEditData(field: any, inputData: any, originalFieldData: any): any { - const files = this.getFieldEditFiles(field), - values = [], - fieldName = 'f_' + field.id + '_alttext'; + const files = this.getFieldEditFiles(field); + const fieldName = 'f_' + field.id + '_alttext'; - if (files.length) { - values.push({ + return [ + { fieldid: field.id, subfield: 'file', files: files - }); - } - - if (inputData[fieldName]) { - values.push({ + }, + { fieldid: field.id, subfield: 'alttext', value: inputData[fieldName] - }); - } - - return values; + } + ]; } /** diff --git a/src/addon/mod/data/fields/radiobutton/providers/handler.ts b/src/addon/mod/data/fields/radiobutton/providers/handler.ts index 6efbd744b..a58b407bf 100644 --- a/src/addon/mod/data/fields/radiobutton/providers/handler.ts +++ b/src/addon/mod/data/fields/radiobutton/providers/handler.ts @@ -67,14 +67,10 @@ export class AddonModDataFieldRadiobuttonHandler implements AddonModDataFieldHan getFieldEditData(field: any, inputData: any, originalFieldData: any): any { const fieldName = 'f_' + field.id; - if (inputData[fieldName]) { - return [{ - fieldid: field.id, - value: inputData[fieldName] - }]; - } - - return false; + return [{ + fieldid: field.id, + value: inputData[fieldName] || '' + }]; } /** diff --git a/src/addon/mod/data/fields/text/providers/handler.ts b/src/addon/mod/data/fields/text/providers/handler.ts index 19d49b713..1a4fa8c26 100644 --- a/src/addon/mod/data/fields/text/providers/handler.ts +++ b/src/addon/mod/data/fields/text/providers/handler.ts @@ -68,14 +68,10 @@ export class AddonModDataFieldTextHandler implements AddonModDataFieldHandler { getFieldEditData(field: any, inputData: any, originalFieldData: any): any { const fieldName = 'f_' + field.id; - if (inputData[fieldName]) { - return [{ - fieldid: field.id, - value: inputData[fieldName] - }]; - } - - return false; + return [{ + fieldid: field.id, + value: inputData[fieldName] || '' + }]; } /** diff --git a/src/addon/mod/data/fields/textarea/providers/handler.ts b/src/addon/mod/data/fields/textarea/providers/handler.ts index 8ffcdcf4b..1c1a0bc0d 100644 --- a/src/addon/mod/data/fields/textarea/providers/handler.ts +++ b/src/addon/mod/data/fields/textarea/providers/handler.ts @@ -50,32 +50,32 @@ export class AddonModDataFieldTextareaHandler extends AddonModDataFieldTextHandl */ getFieldEditData(field: any, inputData: any, originalFieldData: any): any { const fieldName = 'f_' + field.id; + const files = this.getFieldEditFiles(field, inputData, originalFieldData); + let text = this.textUtils.restorePluginfileUrls(inputData[fieldName] || '', files); + // Add some HTML to the text if needed. + text = this.textUtils.formatHtmlLines(text); - if (inputData[fieldName]) { - const files = this.getFieldEditFiles(field, inputData, originalFieldData); - let text = this.textUtils.restorePluginfileUrls(inputData[fieldName], files); - - // Add some HTML to the text if needed. - text = this.textUtils.formatHtmlLines(text); - - return [{ - fieldid: field.id, - value: text - }, - { - fieldid: field.id, - subfield: 'content1', - value: 1 - }, - { - fieldid: field.id, - subfield: 'itemid', - files: files - } - ]; + // WS does not properly check if HTML content is blank when the field is required. + if (this.textUtils.htmlIsBlank(text)) { + text = ''; } - return false; + return [ + { + fieldid: field.id, + value: text + }, + { + fieldid: field.id, + subfield: 'content1', + value: 1 + }, + { + fieldid: field.id, + subfield: 'itemid', + files: files + } + ]; } /** @@ -104,11 +104,7 @@ export class AddonModDataFieldTextareaHandler extends AddonModDataFieldTextHandl } const found = inputData.some((input) => { - if (!input.subfield) { - return !!input.value; - } - - return false; + return !input.subfield && this.textUtils.htmlIsBlank(input.value); }); if (!found) { diff --git a/src/addon/mod/data/fields/url/component/addon-mod-data-field-url.html b/src/addon/mod/data/fields/url/component/addon-mod-data-field-url.html index f1c018713..90283fe72 100644 --- a/src/addon/mod/data/fields/url/component/addon-mod-data-field-url.html +++ b/src/addon/mod/data/fields/url/component/addon-mod-data-field-url.html @@ -4,4 +4,4 @@ -{{field.name}} \ No newline at end of file +{{value.content}} \ No newline at end of file diff --git a/src/addon/mod/data/pages/edit/edit.ts b/src/addon/mod/data/pages/edit/edit.ts index 270caa0dc..c311a7137 100644 --- a/src/addon/mod/data/pages/edit/edit.ts +++ b/src/addon/mod/data/pages/edit/edit.ts @@ -303,7 +303,7 @@ export class AddonModDataEditPage { this.jsData = { fields: this.fields, - contents: this.entry.contents, + contents: this.utils.clone(this.entry.contents), form: this.editForm, data: this.data, errors: this.errors