-
-
Notifications
You must be signed in to change notification settings - Fork 218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
6345 - Uplift to enketo-core version 5.18.1 #7256
Changes from 1 commit
6a41820
0f04c84
74d0c1b
c858b66
ac16e4b
b424840
57aa8a1
cb7cb2d
ba8c6fb
351b30b
3f59f16
f1f62bc
660456c
ce1c6d1
240efcc
ce93925
eb8b474
322fac7
c11b7ef
3e1cc17
6a9ba75
0bfcf9e
a6e2afa
2436174
131b67c
6254ff2
68c84ae
693a8a8
126878b
f9b0dd1
72b3cf1
731f3e1
450cd7e
c967023
aaa5e11
39aaaf7
cb78fa4
fa0aca0
72d9184
75bfb80
41feb8f
aa2d205
b56d555
cb88e10
d5dda2a
d1701d1
c2ad0a3
5b2a354
de6840f
9eace41
e1f8fca
abf6976
69a3c22
87f8b26
c035718
b8c375d
2e8aa47
1d4db03
1d619ce
9c75516
c559bdb
6e3fbc4
6b27627
1921b97
7b6c7eb
9f68e29
d78b75f
ef71ca0
da16779
b722e00
a6ed0f3
6893b47
532c9a2
68c4a19
1ab3e9e
df08b9c
845b6f0
3cb901c
c2054f9
d5b5db2
5e74a8f
73461a2
84fc7d3
8e688d2
6a47a54
c62ee21
0963a7a
b6f71ce
aa7129d
75b64ee
cf09c9a
acc16ab
209aa6a
cfd1d27
6e080fc
accff65
bad58d1
a7aac57
2280b6c
9a3eeef
c6e7c86
3b35852
a4b0c1c
5aef37c
77c37ab
9c7723f
7c542b5
365d0c4
d50e4bc
04bccff
8f0210f
86da179
77ff144
2e36c13
0dd3d05
ca635f3
64ba0b5
d7acb8d
afce881
c5609a3
ea1d132
9b7e8dd
2eb1ae1
1b78a19
7410a55
d134926
0f2c21d
782d211
484ffb8
a5d69ba
184c21b
29096c0
dc7bd4f
8d7d2d4
ffdda66
4444137
db5c397
4a59cb4
04e0bf7
c7386d4
d09fcfd
f1ba7d0
389dd89
2f1df27
e0a0357
2a5da45
9a4b36b
8fadc16
b4505a6
a6e6b09
410789b
652b7ab
d6f8ce3
af5bd3e
e89d571
0372a16
7c69f7f
9af7b3d
8debd10
fe16217
f07de14
1674637
d63ed71
c0b7da0
6d52eee
10e0a5e
b7522bf
ab5594e
e340b2c
7baac9c
657a5ec
18bf9af
38514dd
096809c
9baff20
2cbb947
9ea7820
530d139
c3b532a
8be75c7
772a4fe
f1411b3
062cdbc
bfddfe7
84f7c5a
5c09d56
8344c85
1edfb59
5832b3f
cab004f
94ec863
693508b
4307554
48333c9
bf328fb
fbc1844
d0b19b6
4bfddb8
3a02072
bf71528
d6b338b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,26 +30,38 @@ function construct(element) { | |
|
||
const Select2Search = window.CHTCore.Select2Search; | ||
|
||
let $textInput = $question.find('input'); | ||
|
||
const value = $textInput.val(); | ||
const disabled = $textInput.prop('readonly'); | ||
$textInput.replaceWith($textInput[0].outerHTML.replace(/^<input /, '<select ').replace(/<\/input>/, '</select>')); | ||
$textInput = $question.find('select'); | ||
const preSelectedOption = $('<option></option>') | ||
.attr('value', value) | ||
.text(value); | ||
$textInput.append(preSelectedOption); | ||
|
||
const contactTypes = getContactTypes($question, $textInput); | ||
const $textInput = $question.find('input'); | ||
const $proxyInput = $textInput.clone(); | ||
|
||
const $option = $('<option></option>'); | ||
const setOptionValue = value => $option.attr('value', value).text(value); | ||
setOptionValue($textInput.val()); | ||
$textInput.on('inputupdate', () => setOptionValue($textInput.val())); | ||
|
||
$textInput.hide(); | ||
$textInput.after($proxyInput); | ||
$proxyInput.replaceWith( | ||
$proxyInput[0].outerHTML | ||
.replace(/^<input /, '<select ') | ||
.replace(/<\/input>/, '</select>') | ||
); | ||
|
||
const $selectInput = $question.find('select'); | ||
$selectInput.append($option); | ||
$selectInput.on('change.dbobjectwidget', () => { | ||
const selected = $selectInput.select2('data'); | ||
const id = selected && selected[0] && selected[0].id; | ||
$textInput.val(id); | ||
}); | ||
|
||
if (!$question.hasClass('or-appearance-bind-id-only')) { | ||
$textInput.on('change.dbobjectwidget', changeHandler); | ||
$selectInput.on('change.dbobjectwidget', changeHandler); | ||
} | ||
const contactTypes = getContactTypes($question, $selectInput); | ||
const allowNew = $question.hasClass('or-appearance-allow-new'); | ||
Select2Search.init($textInput, contactTypes, { allowNew }).then(function() { | ||
Select2Search.init($selectInput, contactTypes, { allowNew }).then(function() { | ||
// select2 doesn't understand readonly | ||
$textInput.prop('disabled', disabled); | ||
$selectInput.prop('disabled', $textInput.prop('readonly')); | ||
}); | ||
} | ||
|
||
|
@@ -75,7 +87,7 @@ const changeHandler = function() { | |
const doc = selected && selected[0] && selected[0].doc; | ||
if (doc) { | ||
const field = $this.attr('name'); | ||
const index = $('[name="' + field + '"]').index(this); | ||
const index = $('select[name="' + field + '"]').index(this); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So we end up having one hidden input and a select with the same name? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes that is where things sit now.
It is not required that they have the same name. Things go bad in the Enketo logic if I change the name on the |
||
const keyRoot = field.substring(0, field.lastIndexOf('/')); | ||
updateFields(doc, keyRoot, index, field); | ||
// https://github.com/enketo/enketo-core/issues/910 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For all intents and purposes, I like this refactor.
Turning an
input
into aselect
just makes me nervous ...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not meaning to add more work on your plate but, since we're already refactoring this, what is the value of cloning the input and then changing the tag versus just making a new select element?
Is it because there are classes and attributes to copy? Are they actually needed on the select?
This is similar to my question above about the duplicated name.
Could there be bugs if we suddenly have two elements that match an old query, be it an attribute or name search?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call on the cloning! I had forgotten to circle back to that after I got everything else cleaned up. I went back and did some more testing and found that I could just use a brand new
select
element without copying anything (besides thename
as discussed above).I think the only thing we need to decide here is what we should use as the name for the the
select
s. I have left the name of theselect
the same as theinput
for now since it simplifies logic downstream in thechangeHandler
, but we can change that (as I mentioned above). I would just need to include some other way of getting the field path into thechangeHandler
function...