Answer the question
In order to leave comments, you need to log in
How to load phone mask in modal window of uikit framework?
On one page there is an open form for collecting contacts (everything works) and a form in a modal window. How to run phone mask script on modal window open?
<div id="soft-contact" uk-modal>
<div class="uk-modal-dialog uk-modal-body">
<form class="uk-grid-small" id="how2buy" method="post" action="product.html#how2buy" uk-grid>
<div class="uk-width-1-1">
<input class="uk-input" type="tel" id="phone" placeholder=" " name="phone" value="">
<input class="uk-checkbox" type="checkbox" id="phone_mask" checked><label id="descr" for="phone_mask">Check if input is correct</label>
</div>
<div class="uk-width-1-1 uk-text-right">
<button type="submit" class="uk-button uk-width-1-1">Send</button>
</div>
</form>
</div>
</div>
<script>
var maskList = $.masksSort($.masksLoad("/phone-codes.json"), ['#'], /[0-9]|#/, "mask");
var maskOpts = {
inputmask: {
definitions: {
'#': {
validator: "[0-9]",
cardinality: 1
}
},
//clearIncomplete: true,
showMaskOnHover: false,
autoUnmask: true,
clearMaskOnLostFocus: false
},
match: /[0-9]/,
replace: '#',
list: maskList,
listKey: "mask",
onMaskChange: function(maskObj, completed) {
if (completed) {
var hint = maskObj.name_en;
if (maskObj.desc_en && maskObj.desc_en != "") {
hint += " (" + maskObj.desc_en + ")";
}
$("#descr").html(hint);
} else {
$("#descr").html("Check if input is correct");
}
$(this).attr("placeholder", $(this).inputmask("getemptymask"));
}
};
$('#phone_mask').change(function() {
if ($('#phone_mask').is(':checked')) {
$('#phone').inputmasks(maskOpts);
} else {
$('#phone').inputmask("+[####################]", maskOpts.inputmask)
.attr("placeholder", $('#phone').inputmask("getemptymask"));
$("#descr").html("Check if input is correct");
}
});
$('#phone_mask').change();
</script>
Answer the question
In order to leave comments, you need to log in
UIkit.util.on('#soft-contact', 'beforeshow', function () {
// do something
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question