Skip to content

Commit 6e55b60

Browse files
fixed inputmask widget (abandon jquery)
1 parent 2ac3abf commit 6e55b60

File tree

3 files changed

+25
-11
lines changed

3 files changed

+25
-11
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "surveyjs-widgets",
3-
"version": "0.12.49",
3+
"version": "0.12.50",
44
"scripts": {
55
"start": "npm run build && live-server",
66
"prebuild": "webpack --env.buildType dev",

src/inputmask.js

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import Inputmask from "inputmask";
2+
13
function init(Survey) {
24
var widget = {
35
name: "maskedit",
@@ -20,11 +22,12 @@ function init(Survey) {
2022
Survey.JsonObject.metaData.addProperties("matrixdropdowncolumn", properties);
2123
Survey.JsonObject.metaData.addProperties("multipletextitem", properties);
2224
},
23-
applyInputMask: function(surveyElement, $el) {
25+
applyInputMask: function(surveyElement, el) {
2426
var rootWidget = this;
2527
var mask = surveyElement.inputMask != "none" ? surveyElement.inputMask : surveyElement.inputFormat;
2628
var options = {};
2729
if(surveyElement.inputMask != "none") options.inputFormat = surveyElement.inputFormat;
30+
2831
if(surveyElement.inputMask == "currency" || surveyElement.inputMask == "decimal") {
2932
options.groupSeparator = rootWidget.numericGroupSeparator;
3033
options.autoGroup = rootWidget.numericAutoGroup;
@@ -35,32 +38,37 @@ function init(Survey) {
3538
options.prefix = rootWidget.numericPrefix;
3639
options.placeholder = rootWidget.numericPlaceholder;
3740
}
38-
$el.inputmask(mask, options);
41+
if (surveyElement.inputMask == "datetime") {
42+
mask = surveyElement.inputFormat;
43+
}
44+
45+
Inputmask(mask, options).mask(el);
3946

40-
var updateHandler = function() {
41-
$el.inputmask({ setvalue: surveyElement.value });
47+
var updateHandler = function() {
48+
el.value = typeof surveyElement.value === "undefined" ? "" : surveyElement.value;
4249
};
4350
surveyElement.valueChangedCallback = updateHandler;
4451
updateHandler();
4552
},
4653
afterRender: function(question, el) {
4754
if(question.getType() != "multipletext") {
48-
var $el = $(el).is("input") ? $(el) : $(el).find("input");
49-
this.applyInputMask(question, $el);
55+
var input = el.querySelector("input") || el;
56+
this.applyInputMask(question, input);
5057
} else {
5158
for(var i = 0; i < question.items.length; i ++) {
5259
var item = question.items[i];
5360
if(item.inputMask != "none" || item.inputFormat) {
54-
var $el = $(el).find("#" + item.id);
55-
if($el) {
56-
this.applyInputMask(item, $el);
61+
var input = el.querySelector("#" + item.id);
62+
if (input) {
63+
this.applyInputMask(item, input);
5764
}
5865
}
5966
}
6067
}
6168
},
6269
willUnmount: function(question, el) {
63-
$(el).find("input").inputmask('remove');
70+
var input = el.querySelector("input") || el;
71+
input.inputmask.remove();
6472
}
6573
}
6674

webpack.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ module.exports = function(options) {
108108
commonjs2: 'jquery',
109109
commonjs: 'jquery',
110110
amd: 'jquery'
111+
},
112+
'inputmask': {
113+
root: 'Inputmask',
114+
commonjs2: 'inputmask',
115+
commonjs: 'inputmask',
116+
amd: 'inputmask'
111117
}
112118
},
113119
plugins: [

0 commit comments

Comments
 (0)