Jump to content

Time input mask


Recommended Posts

Hey Vitalikssssss, 

You can try using this code in the footer of the page: 

 
<script>
window.onload =
function () {
document.getElementById('InlineAddFieldname').addEventListener('input', function (w_e) { //here instead of Fieldname insert the name of the field that should be masked
if (!isNaN(w_e.data) && w_e.data !== ' ') {
if (this.value.length >= 2 && !this.value.includes(':')) {
this.value = this.value.slice(0, 2) > 23 ? 23 : this.value.slice(0, 2) + ':' + this.value.slice(2, 3);
}
if (this.value.length == 3 && this.value.includes(':'))
if (!this.value.includes('0'))
this.value = parseInt(this.value);
else this.value = this.value.slice(0, 2);
if (this.value.length > 3)
this.value = this.value.slice(0, 2) + ':' + (this.value.slice(3, 5) > 59 ? 59 : this.value.slice(3, 5));
prevVal = this.value;
}
else this.value = prevVal;
})
};
</script>

This code however does not process manual pasting of values. If needed, I can try and think of something to avoid this. 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...