From 0cd97619b5fd7bef2c473881ae4601502b9862ed Mon Sep 17 00:00:00 2001 From: Joshua Kuestersteffen Date: Fri, 27 Aug 2021 13:09:21 -0700 Subject: [PATCH] Try to fix up the db-object-widget --- .../src/js/enketo/widgets/db-object-widget.js | 44 +++++-------------- 1 file changed, 11 insertions(+), 33 deletions(-) diff --git a/webapp/src/js/enketo/widgets/db-object-widget.js b/webapp/src/js/enketo/widgets/db-object-widget.js index d25231ad67e..343bbc51dca 100644 --- a/webapp/src/js/enketo/widgets/db-object-widget.js +++ b/webapp/src/js/enketo/widgets/db-object-widget.js @@ -18,46 +18,24 @@ * @param {(boolean|{touch: boolean, repeat: boolean})} options options * @param {*=} e event */ - function Dbobjectwidget(element, options) { - this.namespace = pluginName; - Object.assign(this, new Widget(element, options)); - this._init(); + class Dbobjectwidget extends Widget { + _init() { + construct(this.element); + } } - //copy the prototype functions from the Widget super class - Dbobjectwidget.prototype = Object.create(Widget.prototype); - - //ensure the constructor is the new one - Dbobjectwidget.prototype.constructor = Dbobjectwidget; - - Dbobjectwidget.prototype._init = function () { - construct(this.element); - }; - function construct(element) { - - const $question = $(element).parent(mainSelector); - let $textInput = $question.find('input'); - - const disabled = $textInput.prop('readonly'); - const relevant = $textInput.attr('data-relevant'); - const name = $textInput.attr('name'); - - if (relevant) { - $textInput.removeAttr('data-relevant disabled'); - $question.attr('data-relevant', relevant); - $question.attr('disabled', disabled); - $question.attr('name', name); - } - // timeout needed to let setting the value complete before rendering - setTimeout(function () { + setTimeout(function() { + const $question = $( element ); + const Select2Search = window.CHTCore.Select2Search; + let $textInput = $question.find('input'); + const value = $textInput.val(); - $textInput.replaceWith($textInput[0].outerHTML - .replace(/^/, '')); + const disabled = $textInput.prop('readonly'); + $textInput.replaceWith($textInput[0].outerHTML.replace(/^/, '')); $textInput = $question.find('select'); const preSelectedOption = $('') .attr('value', value)