Skip to content

Commit 99e04a3

Browse files
SelectOther - allow external onchange
You can now trigger an `onchange` event on the text input which will now correctly update the UI
1 parent 542c948 commit 99e04a3

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/assets/js/select-other.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
$('<option></option>').text(options.otherText)
2929
);
3030

31-
if (input.val()) {
31+
var inputChange = function () {
3232
var selectedOption = select.children().filter(function () { return $(this).text() == input.val(); });
3333
if (selectedOption.length) {
3434
input.hide();
@@ -39,7 +39,11 @@
3939
$(this).prop('selected', true);
4040
}
4141
});
42+
input.show();
4243
}
44+
}
45+
if (input.val()) {
46+
inputChange();
4347
} else {
4448
input.hide()
4549
}
@@ -53,7 +57,10 @@
5357
input.val(select.val());
5458
}
5559
});
60+
input.on('change', function () {
61+
inputChange();
62+
})
5663

5764
});
5865
}
59-
})(window, jQuery);
66+
})(window, jQuery);

0 commit comments

Comments
 (0)