Get 2024 Templates Mega Bundle!14 Bootstrap, Vue & React Templates + 3 Vector Sets
Get for 99$

Conflict between the inputmask and formValidation components


Could you help me resolve a conflict between the inputmask and formValidation components? When I try to validate a field with inputmask, formValidation doesn't work.

exemplo:
<input class="form-control numberDecimal text-end" id="deliveryFee" name="deliveryFee" value="${this.sale.deliveryFee}"
data-inputmask="'alias': 'currency', 'radixPoint': ',', 'prefix': ''"/>


Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(

Replies (1)


Hi,

We will add this example in the next update here. In the meantime you can refer to the below example:


// Define form element
const form = document.getElementById("kt_docs_formvalidation_inputmask");
const maskOptions = {
"mask" : "(999) 999-9999"
};

// Phone
Inputmask(maskOptions).mask("#kt_inputmask");

var input = form.querySelector("[name=inputmask_input]");
input.addEventListener("change", function() {
// Revalidate it
validator.revalidateField("inputmask_input");
});

// Init form validation rules. For more info check the FormValidation plugin"s official documentation:https://formvalidation.io/
var validator = FormValidation.formValidation(
form,
{
fields: {
"inputmask_input": {
validators: {
notEmpty: {
message: "Inputmask input is required"
},
callback: {
message: "Invalid date",
callback: function (input) {
return Inputmask.isValid(input.value, maskOptions);
}
}
}
},
},

plugins: {
trigger: new FormValidation.plugins.Trigger(),
bootstrap: new FormValidation.plugins.Bootstrap5({
rowSelector: ".fv-row",
eleInvalidClass: "",
eleValidClass: ""
})
}
}
);

// Submit button handler
const submitButton = document.getElementById("kt_docs_formvalidation_inputmask_submit");
submitButton.addEventListener("click", function (e) {
// Prevent default button action
e.preventDefault();

// Validate form before submit
if (validator) {
validator.validate().then(function (status) {
console.log("validated!");

if (status == "Valid") {
// Show loading indication
submitButton.setAttribute("data-kt-indicator", "on");

// Disable button to avoid multiple click
submitButton.disabled = true;

// Simulate form submission. For more info check the plugin"s official documentation: https://sweetalert2.github.io/
setTimeout(function () {
// Remove loading indication
submitButton.removeAttribute("data-kt-indicator");

// Enable button
submitButton.disabled = false;

// Show popup confirmation
Swal.fire({
text: "Form has been successfully submitted!",
icon: "success",
buttonsStyling: false,
confirmButtonText: "Ok, got it!",
customClass: {
confirmButton: "btn btn-primary"
}
});

//form.submit(); // Submit form
}, 2000);
}
});
}
});


HTML:


<!--begin::Form-->
<form class="form" action="#" autocomplete="off">
<!--begin::Input group-->
<div class="fv-row mb-10">
<!--begin::Label-->
<label class="required fw-semibold fs-6 mb-2">Date:</label>
<!--end::Label-->

<!--begin::Input-->
<input class="form-control form-control-solid" name="inputmask_input" placeholder="Pick a date" />
<!--end::Input-->

<div class="form-text">
Custom date format: <code>mm/dd/yyyy</code>
</div>
</div>
<!--end::Input group-->

<!--begin::Actions-->
<button type="submit" class="btn btn-primary">
<span class="indicator-label">
Validation Form
</span>
<span class="indicator-progress">
Please wait... <span class="spinner-border spinner-border-sm align-middle ms-2"></span>
</span>
</button>
<!--end::Actions-->
</form>
<!--end::Form-->


Then recompile your assets folder with Gulp or Webpack.

Please note that the build tools are required only in the development environment just to compile the assets when the source folder files are modified. In the hosting/server deployment, you will only need the compile assets, no need to install the build tools dependencies there.

Regards.


Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(